Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top