P peterzatko New Member Oct 10, 2011 #1 I need convert from decimal to hexadecimal.Example number 208 to D0.In mikrobasic.Thx
Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member Oct 11, 2011 #2 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
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
P Pommie Well-Known Member Most Helpful Member Oct 11, 2011 #3 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: Oct 11, 2011
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.
P Pommie Well-Known Member Most Helpful Member Oct 11, 2011 #6 The above does binary to hexadecimal!! If you mean something else then explain what you need better. Mike.
The above does binary to hexadecimal!! If you mean something else then explain what you need better. Mike.
P Pommie Well-Known Member Most Helpful Member Oct 11, 2011 #8 Post what doesn't work and we will help correct it. Mike.
Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member Oct 11, 2011 #9 peterzatko said: How it create in mikrobasic Click to expand... You really could do with a small book on numbering systems and conversion, this is really basic maths.
peterzatko said: How it create in mikrobasic Click to expand... You really could do with a small book on numbering systems and conversion, this is really basic maths.
P peterzatko New Member Oct 11, 2011 #10 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.
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.
Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member Oct 11, 2011 #11 Binay IS decimal... well the integer part anyway! binay_number / 16 = hex_part_upper and binary_number mod 16 is hex_part_lower
Binay IS decimal... well the integer part anyway! binay_number / 16 = hex_part_upper and binary_number mod 16 is hex_part_lower