|
|
|
|
|
Freescale Forums :
Freescale Product Forums :
8-Bit MCU :
Re: CONVERT HEX ASCII string TO DECIMAL ASCII string
|
|
|
|
|

|
Re: CONVERT HEX ASCII string TO DECIMAL ASCII string
|
|
Alban
Super Contributor
Posts: 1266
Registered: 2006-01-18

Message 11 of 13

Viewed 6,682 times
|

|
|
It's very good it doesn't fit in PM:
Everyone can benefit from it, this way 
www.k-noo.net
PROFILE DE-ACTIVATED, Please see Nabla69, my new profile.
|
|
|
|
2006-11-17 03:48 PM
|
|
|
|

|
Re: CONVERT HEX ASCII string TO DECIMAL ASCII string
|
|
ganimides
Contributor
Posts: 37
Registered: 2006-05-12

Message 12 of 13

Viewed 6,675 times
|

|
|
Dear Ware,thank you very ,very ,very,very much for your reliable contribution!.Sorry but I couldn`t reply to thank you before. I`ll test it and I`m sure it`s gonna work out. Kindly regards. Ganimides
|
|
|
|
2006-11-21 08:19 PM
|
|
|
|

|
Re: CONVERT HEX ASCII string TO DECIMAL ASCII string
[ Edited ]
|
|
bigmac
Super Contributor
Posts: 1895
Registered: 2006-02-11

Message 13 of 13

Viewed 6,673 times
|

|
|
Hello Ganimides,
Ganimides wrote in a sequence of PMs - HEX to DECIMAL routine. I just wanted to code in C lenguage some kind of routine to convert HEX to DECIMAL routine. How should I write this example in C? 5CB2h = 2*1 + 11*16 + 12*256 + 5*4096 = 23730 I have a LCD routine that converts to ASCII by a functions called Datos4bits((value%10) +0x30); How Do I put the Hex to decimal routine into my LCD routine?.
------------ I get the data delivered from a proximity card reader in HEXA.I made an array of 10 elements each one of 8 bits. These 11 elements are according to the ID card and these are 5 bytes. When I start up my routine reads the data string and is ddisplayed in HEX format. For example my personal card delivers 2548D4 in hexa when I read on my LCD but in decimal it`s 2443476 that it is my real card numer identifying me. I just need some routine that converts this HEXA into decimal so that my LCD shows 2443476.
------------ My array is about 10 elements each one of 1 byte as follows: RFID [0]=02 RFID [1]=05 RFID [2]=04 RFID [3]=08 RFID [4]=0D RFID [5]=04 I need to convert it to decimal and show it to my LCD in decimal format. THe equivalent would be 2443476 (this is my real personal card) but nowaday I`m showing 2548D4 on my LCD display.
Your raw data within the array RFID occupies the first six bytes of the array, with only the lower nybble of each byte being significant. These nybble values are strictly 4-bit binary values that you have chosen to express as hexadecimal digits, a convenient "shorthand". I would suggest that the display task occur in the following stages - - Combine the nybble data within RFID, to give a 24-bit binary value. In C, this would be expressed as an unsigned long or dword value (32 bits length).
- Convert the binary value to a "packed BCD" format of up to 8 digits, contained in four bytes (dword value).
- Unpack each BCD value, convert to ASCII, and display the value to LCD. Alternatively, each ASCII value could be entered in a string array, and the whole string then sent to the LCD.
The attached code attempts to demonstrate this process. I have actually chosen to accumulate the ASCII characters within a string array variable. This process has similarities to that you have previously used to display the contents of a RTC device. The function I have used to convert to packed BCD format should be more compact and faster than other alternatives that use integer divide operations. Regards, Mac Message Edited by bigmac on 2006-11-2203:05 PM
|
|
|
|
2006-11-22 05:00 AM
|
|
|
|
|
|