PDA

View Full Version : Convert 3-byte hex to dec to display on LCD



lab310
- 10th June 2005, 10:54
I'm doing some fp calculus and result is stored in 3 byte's. How to display this value on LCD in decimal presentation?
For example, a1= 3f, a2=12, a3= 34
h 3f1234 = 4133428, and this is a value to display on LCD (or serial port).

DynamoBen
- 10th June 2005, 14:28
My suggestion would be to mathematically combine the digits into a single value then:

LCDout $FE,$C0,[dec calculatedvalue]

lab310
- 10th June 2005, 16:09
Can't do that since PBP doesn't handle >16bit variables, and I have 24bit.

DynamoBen
- 10th June 2005, 16:26
How about:

LCDout $FE,$C0,[dec a1,dec a2,dec a3]

Luciano
- 10th June 2005, 19:20
Hi!

Just do an addition like you would do on paper without a calculator.

The multipliers used below are the single HEX digits.
(Multipliers for your example: 3=3, F=15, 1=1, 2=2, 3=3, 4=4).

See also the PicBasic "DIG" instruction.

HEX
======
3F1234

DEC
=======
1048576
1048576
1048576
65536
65536
65536
65536
65536
65536
65536
65536
65536
65536
65536
65536
65536
65536
65536
4096
256
256
16
16
16
1
1
1
1
=======
4133428



(3*6)+(15*6)+(1*6)+(2*6)+(3*6)+(4*1)= 148 (write 8)
14+(3*7)+(15*3)+(1*9)+(2*5)+(3*1)= 102 (write 2)
10+(3*5)+(15*5)+(1*0)+(2*2)= 104 (write 4)
10+(3*8)+(15*5)+(1*4)= 113 (write 3)
11+(3*4)+(15*6)= 113 (write 3)
11+(3*0)= 11 (write 1)
1+(3*1)= 4 (write 4)
==============================================

Have fun!

Luciano