Re: Essential Features




"Gary Scott" <garylscott@xxxxxxxxxxxxx> wrote in message
news:EAkaj.359$El5.231@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
James Giles wrote:
garylscott@xxxxxxxxxxxxx wrote:

I realize there are options available for the following code to make
it standard conforming, but this is essential style (e.g. bitwise ands
with integers) and needs to be supported natively, [...]


Well IAND(N, M) already is bitwise AND on integers. It's only
two characters longer than N.and.M (the "I" of I AND and the
comma between the arguments - the parenthesis are the same number
of delimiting characters as the dots around an operator).
You could overload the .and. operator to work on integers,
and that would still be standard conforming code. Of course,
there's still the problem that BOZ constants *aren't* of type
INTEGER (or any other named type). Personally I think
they should be (and should always heve been). You can
get around that by writing a prefix operator:
...
If(iand(iRet, .z.'00000010') .ne. 0) message = trim(message) // &
'Invalid group type (not "WAVE"' // '|'

Yes, I'm fully familiar with all this. It's the function call syntax I
hate. All of the overloading is either available as an extension in all
the compilers I use or it is available in Dan Nagle's portability project
libraries. I just think it's about time for a more boolean-oriented
solution. We have billions of LOC with bitwise operations using .and.,
.or., .shift., .rotate, etc.

...

Unfortunately defined operators can't be implemented by internal
procedures, so you can't count on the above being optimized, by
say inlining or even compile-time evaluation.
I've never done anything with bits and fortran. Nor do I know what LOC is.
Can you describe your query in terms of the following C source?:


#include <stdio.h>
#include <stdlib.h>

const int hamming[256] =
{
0X00, 0X03, 0X05, 0X06, 0X06, 0X05, 0X03, 0X00,
0X07, 0X04, 0X02, 0X01, 0X01, 0X02, 0X04, 0X07,
0X09, 0X0A, 0X0C, 0X0F, 0X0F, 0X0C, 0X0A, 0X09,
0X0E, 0X0D, 0X0B, 0X08, 0X08, 0X0B, 0X0D, 0X0E,
0X0A, 0X09, 0X0F, 0X0C, 0X0C, 0X0F, 0X09, 0X0A,
0X0D, 0X0E, 0X08, 0X0B, 0X0B, 0X08, 0X0E, 0X0D,
0X03, 0X00, 0X06, 0X05, 0X05, 0X06, 0X00, 0X03,
0X04, 0X07, 0X01, 0X02, 0X02, 0X01, 0X07, 0X04,
0X0B, 0X08, 0X0E, 0X0D, 0X0D, 0X0E, 0X08, 0X0B,
0X0C, 0X0F, 0X09, 0X0A, 0X0A, 0X09, 0X0F, 0X0C,
0X02, 0X01, 0X07, 0X04, 0X04, 0X07, 0X01, 0X02,
0X05, 0X06, 0X00, 0X03, 0X03, 0X00, 0X06, 0X05,
0X01, 0X02, 0X04, 0X07, 0X07, 0X04, 0X02, 0X01,
0X06, 0X05, 0X03, 0X00, 0X00, 0X03, 0X05, 0X06,
0X08, 0X0B, 0X0D, 0X0E, 0X0E, 0X0D, 0X0B, 0X08,
0X0F, 0X0C, 0X0A, 0X09, 0X09, 0X0A, 0X0C, 0X0F,
0X0C, 0X0F, 0X09, 0X0A, 0X0A, 0X09, 0X0F, 0X0C,
0X0B, 0X08, 0X0E, 0X0D, 0X0D, 0X0E, 0X08, 0X0B,
0X05, 0X06, 0X00, 0X03, 0X03, 0X00, 0X06, 0X05,
0X02, 0X01, 0X07, 0X04, 0X04, 0X07, 0X01, 0X02,
0X06, 0X05, 0X03, 0X00, 0X00, 0X03, 0X05, 0X06,
0X01, 0X02, 0X04, 0X07, 0X07, 0X04, 0X02, 0X01,
0X0F, 0X0C, 0X0A, 0X09, 0X09, 0X0A, 0X0C, 0X0F,
0X08, 0X0B, 0X0D, 0X0E, 0X0E, 0X0D, 0X0B, 0X08,

0X07, 0X04, 0X02, 0X01, 0X01, 0X02, 0X04, 0X07,
0X00, 0X03, 0X05, 0X06, 0X06, 0X05, 0X03, 0X00,
0X0E, 0X0D, 0X0B, 0X08, 0X08, 0X0B, 0X0D, 0X0E,
0X09, 0X0A, 0X0C, 0X0F, 0X0F, 0X0C, 0X0A, 0X09,
0X0D, 0X0E, 0X08, 0X0B, 0X0B, 0X08, 0X0E, 0X0D,
0X0A, 0X09, 0X0F, 0X0C, 0X0C, 0X0F, 0X09, 0X0A,
0X04, 0X07, 0X01, 0X02, 0X02, 0X01, 0X07, 0X04,
0X03, 0X00, 0X06, 0X05, 0X05, 0X06, 0X00, 0X03,
};

const int ham_pos_values [8] =
{ 3, 5, 6, 7, 9, 10, 11, 12 };

unsigned int corrections [16] =
{
0x00, /* 0 result means no error */
0x00, /* C1 is a Hamming bit, not a data bit */
0x00, /* C2 is a Hamming bit, not a data bit */
0x01, /* C3 is data bit D0 */
0x00, /* C4 is a Hamming bit, not a data bit */
0x02, /* C5 is data bit D1 */
0x04, /* C6 is data bit D2 */
0x08, /* C7 is data bit D3 */
0x00, /* C8 is a Hamming bit, not a data bit */
0x10, /* C9 is data bit D4 */
0x20, /* C10 is data bit D5 */
0x40, /* C11 is data bit D6 */
0x80, /* C12 is data bit D7 */
};

int HammingBitwise(int value)
{
int result = 0;

/* ensure that value is in the allowable */
/* range of 0 through 255 */
value &= 0xff;

/* exclusive OR data bits 0, 1, 3, 4, & 5 */
/* into check bit 0 */
result ^= ((value ) & 1); /* D0 to D0 */
result ^= ((value >> 1) & 1); /* D1 to D0 */
result ^= ((value >> 3) & 1); /* D3 to D0 */
result ^= ((value >> 4) & 1); /* D4 to D0 */
result ^= ((value >> 6) & 1); /* D6 to D0 */

/* exclusive OR data bits 0, 2, 3, 5, & 6 */
/* into check bit 1 */
result ^= ((value << 1) & 2); /* D0 to D1 */
result ^= ((value >> 1) & 2); /* D2 to D1 */
result ^= ((value >> 2) & 2); /* D3 to D1 */
result ^= ((value >> 4) & 2); /* D5 to D1 */
result ^= ((value >> 5) & 2); /* D6 to D1 */

/* exclusive OR data bits 1, 2, 3, & 7 */
/* into check bit 2 */
result ^= ((value << 1) & 4); /* D1 to D2 */
result ^= ((value ) & 4); /* D2 to D2 */
result ^= ((value >> 1) & 4); /* D3 to D2 */
result ^= ((value >> 5) & 4); /* D7 to D2 */

/* exclusive OR data bits 4, 5, 6, & 7 */
/* into check bit 3 */
result ^= ((value >> 1) & 8); /* D4 to D3 */
result ^= ((value >> 2) & 8); /* D5 to D3 */
result ^= ((value >> 3) & 8); /* D6 to D3 */
result ^= ((value >> 4) & 8); /* D7 to D3 */

return result;
}

int HammingPosition(int value)
{
int result = 0;
int counter;

/* ensure that value is in the allowable */
/* range of 0 through 255 */
value &= 0xff;

/* loop through the bits, exclusive OR in */
/* the value for the one bits */
for (counter = 0; counter < 8; ++counter)
{
if ((value & (1 << counter)) != 0)
{
result ^= ham_pos_values[counter];
}
}
return result;
}

int main(void)
{
unsigned long value;
unsigned long modified;
long the_bit;
int ham;
int mod_ham;
char buff[50];

for ( ; ; )
{
printf("Enter a value between 0 and 255 in C notation: ");
fflush(stdout);
if (NULL == (fgets(buff, sizeof buff, stdin)))
{
break;
}
else if (*buff == '\n')
{
break;
}
value = strtoul(buff, NULL, 0);
if (value > 255)
{
puts("Value too large");
continue;
}
printf("Enter the bit (0 - 7) to change: ");
fflush(stdout);
if (NULL == (fgets(buff, sizeof buff, stdin)))
{
break;
}
else if (*buff == '\n')
{
break;
}
the_bit = strtol(buff, NULL, 0);
if (the_bit > 7 || the_bit < 0)
{
puts("Bit number out of range");
continue;
}
ham = hamming[value];
modified = value ^ (1 << the_bit);
mod_ham = hamming[modified];
printf("Original value 0x%02X Hamming Code 0x%X\n",
value, ham);
printf("Modified value 0x%02X Hamming Code 0x%X\n",
modified, mod_ham);
printf("Exclusive OR of the Hamming Codes is 0x%X\n",
ham ^ mod_ham);
printf("Correction mask is 0x%02X\n",
corrections[ham ^ mod_ham]);
printf("Corrected value is 0x%02X\n\n",
modified ^ corrections[ham ^ mod_ham]);
}
printf("\nGoodbye\n");
system("PAUSE");
return 0;
}
I would attribute with the above except that I think that the supposed
attribution were less like Knuth and more like Joseph and his peep-stone.
The good news was that I got to fire up BloodShed, my C compiler of choice.

The better news is that I think I can make a Golay code with the above.
--
Gerry Ford

3 Republican Square
251 Michigan Av.
GR, MI 49503




----== Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups ==----
Get Anonymous, Uncensored, Access to West and East Coast Server Farms at!
----== Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM ==----
.



Relevant Pages

  • Re: how to set default values in instantiating a generic List<>
    ... int, it seems clear that this is actually bitwise data... ... but with proper handling of the enum as a bitwise entity. ... I know that this doesn't answer your question with lists, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Please tell me if Ive written this correctly
    ... Nils Petter Vaskinn wrote: ... > Bitwise AND & ... > int c, space; ...
    (comp.lang.c)
  • Re: exponential identity seed
    ... > are an int and a varchar. ... > This way I can store and manage the selected preferences using bitwise ... > To avoid problems I would like to auto-generate this exponential sequence ...
    (microsoft.public.sqlserver.programming)
  • Re: Auditing C code
    ... know or care about the difference between int, int16_t, unsigned int, ... He does a lot of bitwise |, &, etc on signed int, without ... parameters, to make sure that all passed parameters are of the same type, ...
    (comp.lang.c)