Large integers and bitwise operation
diafysal
Posts: 92
Could someone please translate this:
NegMask CON %1111100000000000 ' For 11-bit negative to 16-bits
IF (y.BIT10 = 1) THEN y = y | NegMask ' Store 11-bits as signed word
(from "TestHm55bCompass.bs2" )
NegMask CON %1111100000000000 ' For 11-bit negative to 16-bits
IF (y.BIT10 = 1) THEN y = y | NegMask ' Store 11-bits as signed word
(from "TestHm55bCompass.bs2" )
Comments
That is because negative numbers are stored in 2-complement.
-1 is %1111111111111111
If you define b10 to be the sign bit, all bits higher than b10 must be
set to 1 if b10 is 1.
regards peter
if ((y & %0000010000000000) != 0) y |= %1111100000000000;
regards peter
Post Edited (Peter Verkaik) : 7/25/2005 7:53:37 AM GMT
I have got the feeling that i only can write numbers in dec. hex. or octal.
what about this:
if (y > 1023) {
y = y << 5;
y = y >> 5;
}
?
·· if ((y & 0x0400) != 0) y |= 0xF800;
regards peter
·
Error.... .. main contains a constant out of range...
because of the " 0xf800 " I think.
if ((y & 0x0400) != 0) {
y = y << 5;
y = y >> 5;
}
For converting 11bit signed integer to 16bit signed integer.
·· if ((y & 0x0400) != 0) y |= (short)0xF800;
regards peter
·
Is " (short)0xf800 " a way to trick the javelin stamp IDE?
*continues testing*
Where int has a range -32768 to +32767,
a short has a range 0 to 65535.
Both types can represent 0x0000 to 0xFFFF but they
are interpreted differently.
regards peter
regards Lars