How to create function Hex to Dec ?

Post Reply
Rachata.rath
Posts: 8
Joined: Fri Mar 13, 2015 3:12 pm

How to create function Hex to Dec ?

Post by Rachata.rath »

How to convert hex to dec ?
Example 0xA1 convert to decimal ?
I read from user manual no have this function
Thank you

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: How to create function Hex to Dec ?

Post by Mr. Kibernetik »

No, currently there is no built-in function to convert HEX to DEC.

Rachata.rath
Posts: 8
Joined: Fri Mar 13, 2015 3:12 pm

Re: How to create function Hex to Dec ?

Post by Rachata.rath »

Do you have example code ?

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: How to create function Hex to Dec ?

Post by Mr. Kibernetik »

Rachata.rath wrote:Do you have example code ?
Which example code?

Rachata.rath
Posts: 8
Joined: Fri Mar 13, 2015 3:12 pm

Re: How to create function Hex to Dec ?

Post by Rachata.rath »

Hex to dec?
Hex is 0xA1 I want to convert to dec

Dec = HexTODec$(0xA1)
Print Dec

Def HexTODec$()
...
....
End def

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: How to create function Hex to Dec ?

Post by Mr. Kibernetik »

You can make such function yourself. There is no such function in smart BASIC.

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: How to create function Hex to Dec ?

Post by Dutchman »

The following program contains a HexToDec-function.
There is no errordetection incorporated!!

Code: Select all

'Hex-Dec calculator
'by Dutchman, march 2015

Hex$="A1"
PRINT "Hexadecimal number '";Hex$;"' = Decimal ";HexToDec(Hex$)
END

DEF HexToDec(IN$)
Base=OPTION_BASE()' save option base
OPTION BASE 0
HEX$="0123456789ABCDEF"
Dec=0
size=LEN(In$)
FOR pos=0 TO Size-1'pos=backward position
  n=size-pos-1'n=forward position
  c$=MID$(In$,n,1)
  val=INSTR(Hex$,CAPSTR$(c$))
  Dec+=16^(pos)*val
NEXT pos
OPTION BASE Base
HexToDec=Dec
END DEF

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: How to create function Hex to Dec ?

Post by Mr. Kibernetik »

Version 4.9 will introduce HEX <=> DEC conversion functions.

Post Reply