Johan Schoeman Expert Licensed User Longtime User Aug 19, 2018 #1 I am testing the following code: Code: Copy Dim bb As Byte = -104 Log("bb = " & bb) bb = bb + 256 Log("bb + 256 = " & bb) I need "bb" to be 152 after "bb + 256" was executed. But I am getting "-104". How do I get this to be 152? Can someone please help with this? Even trying Bit.And(bb, 0xFF) gives -104 and not 152.
I am testing the following code: Code: Copy Dim bb As Byte = -104 Log("bb = " & bb) bb = bb + 256 Log("bb + 256 = " & bb) I need "bb" to be 152 after "bb + 256" was executed. But I am getting "-104". How do I get this to be 152? Can someone please help with this? Even trying Bit.And(bb, 0xFF) gives -104 and not 152.
Star-Dust Expert Licensed User Longtime User Aug 19, 2018 #2 Byte (-127 .. 127) se this Code: Copy Dim bb As Byte = -104 Log("bb = " & bb) Dim bs As Short = 256 + bb Log("bb + 256 = " & bs) Upvote 0
Byte (-127 .. 127) se this Code: Copy Dim bb As Byte = -104 Log("bb = " & bb) Dim bs As Short = 256 + bb Log("bb + 256 = " & bs)
Johan Schoeman Expert Licensed User Longtime User Aug 19, 2018 #3 Star-Dust said: Byte (-127 .. 127) se this Code: Copy Dim bb As Byte = -104 Log("bb = " & bb) Dim bs As Short = 256 + bb Log("bb + 256 = " & bs) Click to expand... Where have you been all day.....! Code: Copy Dim bb As Byte = -104 Log("bb = " & bb) Dim bs As Short = 256 + bb bb = bs Log("bbnew + 256 = " & bs) Upvote 0
Star-Dust said: Byte (-127 .. 127) se this Code: Copy Dim bb As Byte = -104 Log("bb = " & bb) Dim bs As Short = 256 + bb Log("bb + 256 = " & bs) Click to expand... Where have you been all day.....! Code: Copy Dim bb As Byte = -104 Log("bb = " & bb) Dim bs As Short = 256 + bb bb = bs Log("bbnew + 256 = " & bs)
Star-Dust Expert Licensed User Longtime User Aug 19, 2018 #4 I read you carefully, but I did not understand the problem. Unfortunately I do not understand English well. On the other hand I understand B4X and with the example I understood the problem Upvote 0
I read you carefully, but I did not understand the problem. Unfortunately I do not understand English well. On the other hand I understand B4X and with the example I understood the problem
Johan Schoeman Expert Licensed User Longtime User Aug 19, 2018 #5 Star-Dust said: I read you carefully, but I did not understand the problem. Unfortunately I do not understand English well. On the other hand I understand B4X and with the example I understood the problem Click to expand... OK - same problem. How do I get bb to be 152. Logging bs gives 152 but doing bb = bs and then logging bb still gives -104. I need bb (byte) to be 152.... The below code logs -104 for bb but 152 for bs. I need bb to be 152... Code: Copy Dim bb As Byte = -104 Dim bs As Short = 256 + bb bb = bs Log("bbnew + 256 = " & bb) Upvote 0
Star-Dust said: I read you carefully, but I did not understand the problem. Unfortunately I do not understand English well. On the other hand I understand B4X and with the example I understood the problem Click to expand... OK - same problem. How do I get bb to be 152. Logging bs gives 152 but doing bb = bs and then logging bb still gives -104. I need bb (byte) to be 152.... The below code logs -104 for bb but 152 for bs. I need bb to be 152... Code: Copy Dim bb As Byte = -104 Dim bs As Short = 256 + bb bb = bs Log("bbnew + 256 = " & bb)
Star-Dust Expert Licensed User Longtime User Aug 19, 2018 #6 The byte type can not contain a positive number superior to 127. They are 8 bits, it first bit is used only for the sign. The other 7 bits are used to represent a number 0 127 Upvote 0
The byte type can not contain a positive number superior to 127. They are 8 bits, it first bit is used only for the sign. The other 7 bits are used to represent a number 0 127
Johan Schoeman Expert Licensed User Longtime User Aug 19, 2018 #7 Star-Dust said: The byte type can not contain a positive number superior to 127. They are 8 bits, it first bit is used only for the sign. The other 7 bits are used to represent a number 0 127 Click to expand... Hmmmm.....that is true. Need to rethink how I am going to solve this. Issue is that there are a number of bytes in the byte() array that are less than 0 and they all yield "0xfffd" and not the hex values that I need. Thanks for your help. Much appreciated! Upvote 0
Star-Dust said: The byte type can not contain a positive number superior to 127. They are 8 bits, it first bit is used only for the sign. The other 7 bits are used to represent a number 0 127 Click to expand... Hmmmm.....that is true. Need to rethink how I am going to solve this. Issue is that there are a number of bytes in the byte() array that are less than 0 and they all yield "0xfffd" and not the hex values that I need. Thanks for your help. Much appreciated!
Star-Dust Expert Licensed User Longtime User Aug 19, 2018 #8 Instead of bytes, you can use char and then do a casting with int? Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Aug 20, 2018 #9 Johan Schoeman said: Issue is that there are a number of bytes in the byte() array that are less than 0 and they all yield "0xfffd" and not the hex values that I need. Click to expand... You are doing something. Post the relevant code. In most cases it shouldn't matter that the bytes are signed bytes. You can convert a signed byte to unsigned value with: Code: Copy Dim ub As Int = Bit.And(0xff, SignedByte) Upvote 0
Johan Schoeman said: Issue is that there are a number of bytes in the byte() array that are less than 0 and they all yield "0xfffd" and not the hex values that I need. Click to expand... You are doing something. Post the relevant code. In most cases it shouldn't matter that the bytes are signed bytes. You can convert a signed byte to unsigned value with: Code: Copy Dim ub As Int = Bit.And(0xff, SignedByte)