PDA

View Full Version : about Hex to Decimal



primo
19-08-2019, 11:47
when we peek the Unicode character:
string uniode = "Я"
hx_str = PEEKHex$(strptr(unicode), 2)
we get correctly D0AF like displayed in this page for that Character:
https://www.compart.com/en/unicode/U+042F
under the title: UTF-8 Encoding: 0xD0 0xAF
and this is equivalent to the Decimal 53423
15*16^0 + 10*16^1 + 0*16^2 +13*16^3 = 15 + 160 + 0 + 53248 = 53423
but i got from the following code -12113

hex to decimal calculator : https://tools.keycdn.com/hex-converter?value=D0AF&input=hex


Uses "Console"

string unicode = "Я"
string hx_str
hx_str = PEEKHex$(strptr(unicode), 2)
printl hx_str
hx_str = "&h" + hx_str
print val(hx_str)

waitkey

PS:
it is possible because 65535 = 53248 + 12113

ErosOlmi
19-08-2019, 14:29
https://www.thinbasic.com/public/products/thinBasic/help/html/index.html?val.htm

Because VAL of an HEX string return signed or unsigned depending if string has a leading zero.


Uses "Console"
string unicode = "Я"
string hx_str
hx_str = PEEKHex$(strptr(unicode), 2)
printl hx_str
'hx_str = "&h" + hx_str
printl "Signed:" , val("&h" + hx_str)
printl "Unsigned:", val("&h0" + hx_str)

waitkey



D0AF
Signed: -12113
Unsigned: 53423