PDA

View Full Version : Convert dec/binary to Hex



SagemFree
- 10th May 2005, 19:10
I read numerous post in the forum but did not find the answer to my problem.
In fact, i wish to find a routine to obtain the same result as "HEX2" used with "LCDOUT".
I explain, I need to read the 64 bits registered number in the 1 wire Dallas composant but i use a LCD which not allow the command for HD44780 normally use with PBP and consequantly cannot use "LCDOUT".
In my LCD the text is displayed with the use of "LOOKUP2" and each caracter are sent in ASCII.
The info in the 1 Wire has to be read in HEX and i dont know how i can obtain the correspondig result allowing to display same .
I hope i was sufficient clear and that somebody can help.

Luciano
- 10th May 2005, 22:52
Hi,

To convert a decimal number under 256 to a two-digit hex number,
divide the number by 16. Write the number of times 16 goes into
the number as the left digit of the hex number (using hex notation).
Write the remainder of the division as the right digit (using hex notation).

For example, try the number 171. Sixteen goes into 171 ten times with a
remainder of 11.

10 is represented by A, and 11 is represented by B in hex notation.

171 = AB

Use the PicBasic LOOKUP statement to return the left and right digit of the hex number.

LOOKUP B0,[“0123456789ABCDEF”],B1

* * *

See PicBasic Pro manual:

4.17.2. Division
(The '//' operator returns the remainder).

5.43. LOOKUP

Best regards,

Luciano

SagemFree
- 11th May 2005, 18:00
Thanks for the help.

Rgds