Didier9 Well-Known Member Licensed User Longtime User Nov 24, 2019 #1 I have a byte array, msg() and I want to check that specific bytes are specific values, like Code: Copy If msg(0) = 0x10 and msg(1) = 0x8F then The problem is that when the byte value is greater than 127, the byte value is converted to a negative 32 bit number. For instance, if the byte is 0x8F, it is converted to 0xFFFFFF8F and of course the comparison fails. There are a number of ugly ways I can think to fix this but really how can I force a byte value to return a 0-255 value?
I have a byte array, msg() and I want to check that specific bytes are specific values, like Code: Copy If msg(0) = 0x10 and msg(1) = 0x8F then The problem is that when the byte value is greater than 127, the byte value is converted to a negative 32 bit number. For instance, if the byte is 0x8F, it is converted to 0xFFFFFF8F and of course the comparison fails. There are a number of ugly ways I can think to fix this but really how can I force a byte value to return a 0-255 value?
Didier9 Well-Known Member Licensed User Longtime User Nov 24, 2019 #2 Looks like I found a clean way. Instead of comparing to 0x8F, I declare a byte variable and compare to that Code: Copy Dim VAR_0x8F as Byte = 0x8F If msg(1) = VAR_0x8F Then and that works. I guess otherwise 0x8F is treated as a 32 bit variable and forces the conversion of msg(1) to 32 bits Last edited: Apr 24, 2020 Upvote 0
Looks like I found a clean way. Instead of comparing to 0x8F, I declare a byte variable and compare to that Code: Copy Dim VAR_0x8F as Byte = 0x8F If msg(1) = VAR_0x8F Then and that works. I guess otherwise 0x8F is treated as a 32 bit variable and forces the conversion of msg(1) to 32 bits