Page 1 of 1

BCD converter

Posted: Sat Jul 03, 2004 6:58 pm
by CraigWes
How do I convert something from BCD to ascii in C/C++? Have tried to port ASM code but I didnt get it to work. Should be used for a time function or something. The code I use now is:

outbyte(0x70,0x4);
unsigned char h = inbyte(0x71);

and I wanna know how to get the current hour out of this number :)

Re:BCD converter

Posted: Sat Jul 03, 2004 8:04 pm
by Curufir

Code: Select all

char hour[2];

outbyte(0x70,0x4);
unsigned char h = inbyte(0x71);

/* h assumed BCD encoded byte sized value */

hour[0] = (char)(((h & 0xf0) >> 4) + 0x30);
hour[1] = (char)((h & 0x0f) + 0x30);
Should do the trick (Untested). Dunno if you need the cast, my C isn't very good, but you should get the idea from that.

Re:BCD converter

Posted: Sun Jul 04, 2004 5:26 am
by CraigWes
Well it works a little better now..but the minute is changed about every second and all that.. and when I reboot bochs, the hour i different..

Re:BCD converter

Posted: Sun Jul 04, 2004 9:02 am
by CraigWes
Sorry man it works great the first time, guess it?s bochs problem that the time changes when I reboot?
me being just as stupid as allways