M mscientist33 Active Member Licensed User Mar 28, 2022 #1 I am getting a byte which should be 192, b4a takes it as a signed byte of -64. How can I use it as unsigned as get my 192?
I am getting a byte which should be 192, b4a takes it as a signed byte of -64. How can I use it as unsigned as get my 192?
B Brian Dean Well-Known Member Licensed User Longtime User Mar 28, 2022 #2 B4X: Copy Dim b as byte Dim i as int .... ... If (b < 0) Then i = b + 256 Else i = b Upvote 0
E emexes Expert Licensed User Longtime User Mar 28, 2022 #3 Unsigned Bytes would be great, although I suspect they'd be implemented as Java Ints or Shorts. B4X: Copy Dim b As Byte = Rnd(-127, 0) Dim OneWay As Int = Bit.And(b, 0xFF) Dim AnotherWay As Int = b Mod 256 Log(b) Log(OneWay) Log(AnotherWay) Last edited: Mar 29, 2022 Upvote 0
Unsigned Bytes would be great, although I suspect they'd be implemented as Java Ints or Shorts. B4X: Copy Dim b As Byte = Rnd(-127, 0) Dim OneWay As Int = Bit.And(b, 0xFF) Dim AnotherWay As Int = b Mod 256 Log(b) Log(OneWay) Log(AnotherWay)
E emexes Expert Licensed User Longtime User Mar 29, 2022 #4 If you're calculating a packet checkvalue by summing packet bytes, you can leave the signed-to-unsigned adjustment until the end. And if the packet checkvalue and your summing variable are both Bytes, then you probably don't even need to do an adjustment at all, because they'll both be subject to the same -128..127 range wraparound. Upvote 0
If you're calculating a packet checkvalue by summing packet bytes, you can leave the signed-to-unsigned adjustment until the end. And if the packet checkvalue and your summing variable are both Bytes, then you probably don't even need to do an adjustment at all, because they'll both be subject to the same -128..127 range wraparound.
M mscientist33 Active Member Licensed User Mar 30, 2022 #5 Ah, I found my problem. I was doing your "oneway" example but I was still declaring a byte instead of an int.... Upvote 0
Ah, I found my problem. I was doing your "oneway" example but I was still declaring a byte instead of an int....