Chuck:
This worked like a champ! Sometimes I forget how to do 1st Grade
math.
Thanks a lot.
Rich
Rich Cini
Collector of classic computers
Lead engineer, Altair32 Emulator
Web site:
http://highgate.comm.sfu.ca/~rcini/classiccmp/
Web site:
http://www.altair32.com/
/***************************************************/
-----Original Message-----
From: cctalk-bounces at
classiccmp.org [mailto:cctalk-bounces at
classiccmp.org]
On Behalf Of Chuck Guzis
Sent: Thursday, June 29, 2006 11:59 PM
To: cctalk at
classiccmp.org
Subject: Re: OT: Hex to BCD conversion for programs
Rich,
It sounds as if your programming language is "C". :)
sprintf() is probably fine for what you want to do, but using the Windows
API to get the time is not terribly portable. How about using some of the
calls in time.h? Say a call to time(), followed by a call to localtime()?
At least that way, your time will be broken out into structure elements
holding month, day, year, hours, minutes, seconds and will be good on just
about any platform. You can create your BCD values by /10 and %10
operations for the upper and lower digits respectively.
Cheers,
Chuck
On 6/29/2006 at 10:51 PM Richard A. Cini wrote:
All:
I'm working on a real-time-clock emulation for the Altair32
and
I need a push on something. Most RTC boards return a
BCD value to the
caller. When you call GetLocalTime in Windows, it returns an integer
value.
So, I have to somehow convert an integer to its BCD
representation.
I thought about using sprintf on the integer and then
returning
str[0] or str[1] depending on if I need the tens place
or units place.
However, this seems to me to be an inelegant way of doing it.
Does anyone have any ready-made C code to do this that I can
use? Thanks a lot!
Rich
Rich Cini
Collector of classic computers
Lead engineer, Altair32 Emulator
Web site: <http://highgate.comm.sfu.ca/~rcini/classiccmp/>
http://highgate.comm.sfu.ca/~rcini/classiccmp/
Web site:
http://www.altair32.com/
/***************************************************/