| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | [--- Ebcdic ---] |
Hi Neil.
02-Nov-03 10:43:02, Neil Heller wrote
NH> I wrote communication programs to download electrical usage
NH> information from industrial meters. Those meters are currently
NH> being produced. One of them stored all values in BCD, and
NH> transmitted them as such. In a situation like that, the receiver
NH> doesn't have much choice.
NH> I did a bunch of BCD work with MSC6, but I ended up having to roll my
NH> own library. Basically it involved shifting for one side of the byte
NH> and masking for the other. The BCD would then be translated into
NH> integer types and the application would proceed from there. Division
NH> was a real bear, though.
// convert the bcd to to ascii
sprintf(buf,"%x",bcd); // not portable - but something likethat...
// convert ascii to two's compliment
number=atol(buf);
probably less efficient than direct manipulating, but if the need is speed
use a lookup tables to convert it a byte (or more?) at a time...
number=0;
for (i=0; i< sizeof_bcd;i++) number=number*100+bcdval[bcd[i]];
or declare a struct with bitfields
struct bcd_value {
unsigned digit3:4;
unsigned digit2:4;
unsigned digit1:4;
unsigned digit0:4;
}
then C will do the bit-masking for you....
-=> Bye <=-
---
* Origin: If at first you don't succeed, the hell with it. (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™.