J
Jorge Peixoto
Yes. Bitwise operators must be implemented as if operating on a binary
So the code here *is* redundant! This call
putc((unsigned)((s.i32 >> 24) & 0xff), fp);
is equivalent to this
putc((unsigned)(s.i32 >> 24), fp);
In the second call, you cast to unsigned char, which means taking the
remainder modulo 256.
In the first call, you perform bitwise and with 0xff; you are telling
me that this will behave (for unsigned numbers, and this one is
unsigned) as if the number was represented in two's complement; so
this is equivalent to taking the remainder modulo 256.
And I think that even the cast to unsigned is unneeded. Can you get
different results from casting an integer to unsigned, then to
unsigned char, instead of directly casting from integer to unsigned
char?
representation of the value, which would presumably not be a simple
operation on such a machine. Trinary machines (which have some
interesting advantages in certain contexts compared to binary machines)
would also be problematic.
So the code here *is* redundant! This call
putc((unsigned)((s.i32 >> 24) & 0xff), fp);
is equivalent to this
putc((unsigned)(s.i32 >> 24), fp);
In the second call, you cast to unsigned char, which means taking the
remainder modulo 256.
In the first call, you perform bitwise and with 0xff; you are telling
me that this will behave (for unsigned numbers, and this one is
unsigned) as if the number was represented in two's complement; so
this is equivalent to taking the remainder modulo 256.
And I think that even the cast to unsigned is unneeded. Can you get
different results from casting an integer to unsigned, then to
unsigned char, instead of directly casting from integer to unsigned
char?