QtechLab Active Member Licensed User Longtime User Jun 1, 2015 #1 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. Code: Copy Sub Byte2Unsigned(B As Byte) As Byte Return Bit.AND(B, 0xFF) End Sub In this way the function is working perfectly! Code: Copy 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
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. Code: Copy Sub Byte2Unsigned(B As Byte) As Byte Return Bit.AND(B, 0xFF) End Sub In this way the function is working perfectly! Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Jun 1, 2015 #2 I'm unable to reproduce it. I've tried with this code: Code: Copy log(Byte2Unsigned(1)) It prints 1. Note that bytes in B4i are unsigned (unlike B4A and B4J).
I'm unable to reproduce it. I've tried with this code: Code: Copy log(Byte2Unsigned(1)) It prints 1. Note that bytes in B4i are unsigned (unlike B4A and B4J).
QtechLab Active Member Licensed User Longtime User Jun 1, 2015 #3 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
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
Erel B4X founder Staff member Licensed User Longtime User Jun 1, 2015 #4 I'm sorry but I'm not sure that I understand. Can you post some code that demonstrates the issue?
QtechLab Active Member Licensed User Longtime User Jun 1, 2015 #5 Case 1: Code: Copy 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: Code: Copy 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
Case 1: Code: Copy 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: Code: Copy 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
S sorex Expert Licensed User Longtime User Jun 1, 2015 #6 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
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 Jun 1, 2015 #7 i don't think so... if i debug step to step it work in both ways.
Erel B4X founder Staff member Licensed User Longtime User Jun 1, 2015 #9 Please upload a small project that demonstrates this issue.