Originally Posted by
primo
Hi
the already existing Val function can convert hex string to decimal.
also you can assign a hex string to a Long type variable and it will automaticaly convert the string to decimal number (like in perl language) ie variables (in context)
your example:
'---Load Console Module
Uses "Console"
String hex_str = "&h100"
'Dim As String hex_str = "&h100"
Long numb = hex_str
PrintL numb
If numb = 256 Then PrintL "I am happy"
PrintL Val(hex_str)
PrintL "Press a key to end program"
'---Wait for a key press
WaitKey
Ok , thanks
> > > > But, Eros says :
%MY_CONST = 0X200c000f As Long
PrintL Hex$(%MY_CONST) , %MY_CONST ' works fine
%MY_OTHER_CONST = &h200c000f As Long
PrintL Hex$(%MY_OTHER_CONST) , %MY_OTHER_CONST ' works fine
You can use hex numbers both using Basic notation (&H...) or C notation (0X...)
char_str = "&h10b0"
numb = char_str
PrintL char_str , numb , Val(char_str) ' result 4272 OK
char_str = "&x10b0" ' result 0 , OK format &x not listed
char_str = "0x10b0" ' result 0 , But -> what about Eros remark on C notation ? works with constant, not variables ?
char_str = "0X10B0" ' result 0 , I also tried Uppercase if......
char_str = "0h10b0" ' result 0 , OK Format not listed
char_str = "&b10a0" ' result 2 , OK 'a' is not a binary digit
char_str = "&b1002" ' result 4 , OK '2' is not a binary digit
I think I will write a conversion routine since I have also to cope with assembler '$' notation.
And reject invalid chars in string should be considered as fatal error.
Regards
Dany
Bookmarks