Hello,
Can anyone explain me why I always get a negative "byte" (which doesn't seem to be a byte but a double word) once I store an 8 bit value with bit 7 set?
why is it setting all the other 24 bits aswell?
the code below outputs
byte >ffffff80 >-128
int >80 >128
-128
-128
128
so it seems that a negative 7 bit value, which is just a positive 8 bit value unsigned, is always stored as 32 bit negative value so I must always mask out all the other bits? even the storing of the correct int value gets messed up.
Can anyone explain me why I always get a negative "byte" (which doesn't seem to be a byte but a double word) once I store an 8 bit value with bit 7 set?
why is it setting all the other 24 bits aswell?
the code below outputs
byte >ffffff80 >-128
int >80 >128
-128
-128
128
so it seems that a negative 7 bit value, which is just a positive 8 bit value unsigned, is always stored as 32 bit negative value so I must always mask out all the other bits? even the storing of the correct int value gets messed up.
B4X:
Dim bytes(2) As Byte
Dim byteval As Byte
Dim intval As Int
byteval=Bit.Or(byteval,Power(2,7 ) )
'byteval=Bit.And(byteval,0xff) < this doesn't help either
Log("byte >"&Bit.ToHexString(byteval) &" >"& byteval)
intval=Bit.Or(intval,Power(2,7 ) )
Log("int >"&Bit.ToHexString(intval) &" >"& intval)
bytes(0)=byteval:Log(bytes(0))
bytes(0)=intval:Log(bytes(0))
Log(Bit.And(bytes(0),0xff))