TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Neil Heller
from: Jasen Betts
date: 2003-11-07 06:32:16
subject: [--- Ebcdic ---]

Hi Neil.

05-Nov-03 10:25:00, Neil Heller wrote to Jasen Betts


 JB>> // convert the bcd to to ascii

 JB>> sprintf(buf,"%x",bcd);   // not portable - but something

 NH> That's good, except each of the numbers in the byte had different
 NH> applications in the metering system with which I was working.

 NH> Also you would then have to run the resulting string (buf) through
 NH> a _really_ non-portable function, like atoi().

??? atoi() / atol() is ANSI

the problem with the above sprintf usage is that it relies on the byte
ordering of the BCD matching the machine byte ordering in the integer
"bcd".

 NH> To make things more interesting, integer values were little endian
 NH> but were only 12 bits long.  The 13th bit was the start of the
 NH> next number. That way every 3 bytes held 2 integer values.

use sscanf() instead of atoi() - you can specifiy field widths....

 -=> Bye <=-
---
* Origin: Entropy isn't what it used to be. (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.