Home > Net >  How to convert a hexadecimal bytes to a signed integer?
How to convert a hexadecimal bytes to a signed integer?

Time:01-14

As title, Dim UBI_A1 As String=CShort (" & amp; H "& amp; Turn "E0") 'hexadecimal decimal
Get is 224, but should be - 32 is right the results

Could you tell me how to modify a great god get a signed integer

CodePudding user response:

VB single-byte type declaration only BYTE, but it is unsigned 0 ~ 255; Other integer type is 2 bytes or more bytes, & amp; HE0 casts into other integer cannot be negative,
Single-byte integer to convert a negative number whether need to do a greater than & amp; H7F judgment,
Dim UBI_A1 As Short=CShort (" & amp; H "& amp; "E0")
If UBI_A1 & gt; & H7F Then
UBI_A1=UBI_A1 - & amp; H100
End If

CodePudding user response:

reference 1st floor yishumei response:
VB single-byte type declaration only BYTE, but it is unsigned 0 ~ 255; Other integer type is 2 bytes or more bytes, & amp; HE0 casts into other integer cannot be negative,
Single-byte integer to convert a negative number whether need to do a greater than & amp; H7F judgment,
Dim UBI_A1 As Short=CShort (" & amp; H "& amp; "E0")
If UBI_A1 & gt; & H7F Then
UBI_A1=UBI_A1 - & amp; H100
End the If


But 2 bytes or more with CShort can convert a negative number, is a single byte

CodePudding user response:

refer to the second floor sinat_25869705 response:
but 2 bytes or more with CShort can convert a negative number, is can't single-byte

CShort () after the conversion of data is a double-byte integer, casting a single-byte integer words first fill & amp; H00, the converted value is always positive,

CodePudding user response:

Dim as a byte="& amp; H "& amp; "80"
Dim as short="b & amp; H "& amp; "8000"
Dim as integer="c & amp; H "& amp; "80000000"
Dim d as uint64="& amp; H "& amp; "8000000000000000"

May be able to pick out a couple can

  • Related