porting C code
Lucas Raab
pythongnome at hotmail.com
Fri Jan 14 08:06:17 EST 2005
Peter Hansen wrote:
> Lucas Raab wrote:
>
>> I have the statement: "typedef unsigned long int word32" and later
>> on: "word32 b[3]" referencing the third bit of the integer.
>
>
> If that's really exactly what you have, then you actually have
> something defining an array of three unsigned long integers
> named "b". And even if you didn't have precisely "word32 b[3]",
> but merely a "b[3]" reference somewhere, it would be referencing
> the third element of an array called "b", which is possibly a byte,
> maybe a long, but definitely not a bit.
>
> Maybe showing it as code rather than inline in your text
> would avoid the possibility of confusion.
>
> -Peter
Sorry, the third "byte" is what I meant. As for code samples, I hope the
following will work:
typedef unsigned long int word32 ;
void mu(word32 *a)
{
int i ;
word32 b[3] ;
b[0] = b[1] = b[2] = 0 ;
for( i=0 ; i<32 ; i++ )
{
b[0] <<= 1 ; b[1] <<= 1 ; b[2] <<= 1 ;
if(a[0]&1) b[2] |= 1 ;
if(a[1]&1) b[1] |= 1 ;
if(a[2]&1) b[0] |= 1 ;
a[0] >>= 1 ; a[1] >>= 1 ; a[2] >>= 1 ;
}
a[0] = b[0] ; a[1] = b[1] ; a[2] = b[2] ;
}
The "a[#]" and "b[#]" are the parts that are giving me trouble.
More information about the Python-list
mailing list