Bug? AND 0xFF - 255 failure!!!

QtechLab

Active Member
Licensed User
Longtime User
Goodmorning everyone is reading,

I'm writing here to let you know of a possible bug (i don't know really if it is a bug).

I was writing some code that works on byte conversions and i noticed an issue:

Every time i call this function i'm obtaining 0 (zero) as result of the function.
B4X:
Sub Byte2Unsigned(B As Byte) As Byte  
    Return Bit.AND(B, 0xFF)
End Sub

In this way the function is working perfectly!
B4X:
Sub Byte2Unsigned(B As Byte) As Byte   
    Return Bit.AND(B, 255)
End Sub

Erel can you explain me why the function isn't working with the 0xFF?

Thank in advance,
Marcello Quaglia
 

QtechLab

Active Member
Licensed User
Longtime User
The problem isn't in Byte2Unsigned function but in the BIT.AND(...) with 0xFF bit-mask. If i use 255 instead 0xFF it works. Try to check something on that 0xFF
 

QtechLab

Active Member
Licensed User
Longtime User
Case 1:

B4X:
Return Bit.AND(B, 0xFF)
End sub....

Sub mySub...
Log(Args.Get(0) & " - " & NumFnc.Byte2Unsigned(Args.Get(0)))
End sub
the result of the log is '136 - 0'


Case 2:

B4X:
Return Bit.AND(B, 255)
End sub....

Sub mySub...
Log(Args.Get(0) & " - " & NumFnc.Byte2Unsigned(Args.Get(0)))
End sub
the result of the log is '136 - 136'

Problem is the mask of bit.AND function, i can't get correct result if use hexadecimal mask (0xFF), i get correct result if ude decimal mask (255)...
Hope you understand
 

sorex

Expert
Licensed User
Longtime User
did you try with 0x0ff or 0x00ff aswell?

it might treat 0xff as a negative value (-127) since the 7th bit is set. the extra 0's might shift the negative bit
 

QtechLab

Active Member
Licensed User
Longtime User
i don't think so... if i debug step to step it work in both ways.
 
Top