Android Question Bit.And 0xFF can't function

52manhua

Member
Licensed User
Longtime User
I have checked all this afternoon, can't figure out the reason.

Here is my test code :
B4X:
    Dim key(9) As Byte
     key=Array As Byte(-24,43,-53,67,78,82,91,245,218,190)
          Dim mstr="dsfsdfsdfsdf"
          Dim k As Int=0,j As Int=0
       
          For i = 0 To key.Length-1
            If key(i)<0 Then
                Log("err" & " " & i & key(i))
                key(i)=Bit.And(0xFF,key(i))     
                Log("c " & key(i))
            End If
         
            k = key(i) / mstr.Length
            j = key(i) Mod mstr.Length
            Log("k=" & k & "j=" & j & "i=" & i & "key(i)=" & key(i))         
          Next


As you see, I want to change the Key(i) always to be the Positive value, but failed ~
Any help is Welcome ,Thank you!
 

Attachments

  • QQ截图20160805161316.png
    8.1 KB · Views: 200

sorex

Expert
Licensed User
Longtime User
you wrote that you want the positive value of key(i) and abs(key(i)) is giving you that.

what goes wrong then?
 
Upvote 0

52manhua

Member
Licensed User
Longtime User
you wrote that you want the positive value of key(i) and abs(key(i)) is giving you that.

what goes wrong then?
OK, Maybe there is some expression problem, to be right, I need the 0xFF & val value, not just positive value

As the title says, I want to use 0xFF and to do this, but can't work ~ so be it.
 
Upvote 0

52manhua

Member
Licensed User
Longtime User
OK, Maybe there is some expression problem, to be right, I need the 0xFF & val value, not just positive value

Thanks for mention that,

but 0xff of a byte is the byte value.

To be exactly, I want change a vb6 program to b4a ,then I found b4a value is signed ,someone say use 0xFF can change it
Then I get this result.
what's right way to change it to vb6 style byte ?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
if the value is -10 do you want it to be 10 or still -10?

or do you want to keep adding values and then do the and FF ?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
try this

B4X:
Log(    Bit.ToHexString(-10+256)    )

gives you the expected 0XF6 and not 0xFFFFFFF6

altho it doesn't matter when you store it back into that byte array.
 
Upvote 0

52manhua

Member
Licensed User
Longtime User

Thank you fo your help!

After all, I find the way to change the encrypt/decode program,
It's a Character encoding problem, I change the character to gb2312,
Use the int value replace origin byte variable, no negative, & 0xFF works right~
the word runs right ...
THX
 
Upvote 0

Similar Threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…