BCD converter

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
CraigWes

BCD converter

Post 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 :)
Curufir

Re:BCD converter

Post 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.
CraigWes

Re:BCD converter

Post 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..
CraigWes

Re:BCD converter

Post 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
Post Reply