Help Decimal to hexadecimal

Status
Not open for further replies.
Why? mikrobasic you can write $D0!! Otherwise you would need a function

208 / 16 = 13,, 208 mod 16 = 0 then use a lookup table so you convert 13 to D

Code:
charneeded = lookup(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F) , index
 
It depends what you mean as 208 is already D0.

However, if you mean that you want to convert to the ascii "D0" then something like,
Code:
    num = 208
    fir = num / 16
    sec = num - fir * 16
    fir = fir + 48
    sec = sec + 48
    If fir > 57 Then fir = fir + 7
    If sec > 57 Then sec = sec + 7
should do it.

Alternatively, you could also do something like,
Code:
    dat = "0123456789ABCDEF"
    fir = Mid(dat, num / 16 + 1, 1)
    sec = Mid(dat, num Mod 16 + 1, 1)

I'm not familiar with MicroBasic so the above is generic.

Edit, Ian beat me to it by seconds.

Mike.
 
Last edited:
The above does binary to hexadecimal!!

If you mean something else then explain what you need better.

Mike.
 
i have a 8 bit binary number i convert it to dec and show it on led dsplay - I have it. them i convert 8bit binary number to hexadecimal and show it on display.
 
Binay IS decimal... well the integer part anyway! binay_number / 16 = hex_part_upper and binary_number mod 16 is hex_part_lower
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…