Home > Net >  VB.NET hexadecimal conversion function
VB.NET hexadecimal conversion function

Time:11-10

'hexadecimal conversion (binary, octal, decimal and hexadecimal conversion)
Function ConvertString (ByVal value As String, ByVal fromBase As an Integer, ByVal toBase As Integer)
Dim intValue As Integer=the Convert. ToInt32 (value, fromBase)
Return the Convert. ToString (intValue toBase)
End the Function

How to use hexadecimal conversion to get positive and negative into system, for example, I from the Internet to find the above algorithm, FF01 hexadecimal is converted to a decimal is 65281, but the actual should be - 255, did ask ace told function transformation, always don't understand

CodePudding user response:

Don't think so write code, ff01 actual - 255 is why?

Hexadecimal conversion is a pure mathematical problems
Coding is the computer problems, different computer processing, coding has the original code, radix-minus-one complement and complement, negative expressed with complement, to say a few, and also didn't say clear FF01 high or high before last

CodePudding user response:

This thing, what positive and negative hexadecimal,,,
According to speculation, is to want to turn the hex decimal as you describe,,,,,,,,, spicy, you this FF01 wonky, highest level is the sign bit first, then you are using is short,,, about this problem, there are a lot of trouble in the inside,,,


If you want to convert hexadecimal to decimal, for positive, can directly use & amp; H:
Dim a As Integer="& amp; H "& amp; "000000 ff"
For negative, decide that they want to, a write to a low is few, is the original code, radix-minus-one complement or complement, put the empty place with your other 0 up, sometimes also need to use your mind to learn something even if the building blocks to build up,

CodePudding user response:

X=65281
If x & gt; Then x=x 32767-65536

CodePudding user response:

Hexadecimal negative usually use the original number of complement, said the number of complement for the original radix-minus-one complement + 1, 255 for two bytes 00 ff, 00 ff radix-minus-one complement for FF00 (radix-minus-one complement for the number of binary every invert, 0000, 0000, 1111, 1111 every invert is: 1111 1111 0000 0000, namely FF00), radix-minus-one complement plus 1, FF01, so - 255 for FF01, namely, three bytes - 255, if it is FFFF01
  • Related