Bug? AND 0xFF - 255 failure!!!

Discussion in 'iOS Bugs & Wishlist' started by MarcelloCSI, Jun 1, 2015.

  1. MarcelloCSI

    MarcelloCSI Active Member Licensed 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.
    Code:
    Sub Byte2Unsigned(B As Byte) As Byte  
        
    Return Bit.AND(B, 0xFF)
    End Sub
    In this way the function is working perfectly!
    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    I'm unable to reproduce it. I've tried with this code:
    Code:
    log(Byte2Unsigned(1))
    It prints 1.

    Note that bytes in B4i are unsigned (unlike B4A and B4J).
     
  3. MarcelloCSI

    MarcelloCSI Active Member Licensed 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
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I'm sorry but I'm not sure that I understand. Can you post some code that demonstrates the issue?
     
  5. MarcelloCSI

    MarcelloCSI Active Member Licensed User

    Case 1:

    Code:
    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:
    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
     
  6. sorex

    sorex Expert Licensed 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
     
  7. MarcelloCSI

    MarcelloCSI Active Member Licensed User

    i don't think so... if i debug step to step it work in both ways.
     
  8. sorex

    sorex Expert Licensed User

    that's strange.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Please upload a small project that demonstrates this issue.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice