Author 
Message 
Lew Pitch #1 / 4

decimal to binary
On Tue, 17 Dec 2002 15:13:30 +0100, in comp.lang.c, "Markus Schroeder" Quote:
>Hi; >do you know those cool binary watches which tell you the time in binary >format? I found one at www.thinkgeek.com, it is called "Matrix Binary >Watch". Ohhhh I want this watch!!! :) >To kill time, I decided to exercise reading binary time by writing a prog >that tells you the time in binary format. >OK.. I did most of the work, but now I'm stuck, because I don't know how to >transform decimal into binary numbers... I think it would be the easiest if >i use an array for the binary numbers, and modify the decimal numbers with >the >> or << operator... but I have no idea, how to accomplish this. >Can anyone help me?
How about repeatedly dividing by 2, and using the remainder? Lew Pitcher, Information Technology Consultant, Toronto Dominion Bank Financial Group
(Opinions expressed are my own, not my employer's.)

Sat, 04 Jun 2005 22:19:26 GMT 


CBFalcone #2 / 4

decimal to binary
Quote:
> do you know those cool binary watches which tell you the time in > binary format? I found one at www.thinkgeek.com, it is called > "Matrix Binary Watch". Ohhhh I want this watch!!! :) > To kill time, I decided to exercise reading binary time by > writing a prog that tells you the time in binary format. > OK.. I did most of the work, but now I'm stuck, because I don't > know how to transform decimal into binary numbers... I think it > would be the easiest if i use an array for the binary numbers, > and modify the decimal numbers with the >> or << operator... but > I have no idea, how to accomplish this. Can anyone help me?
putbinary(unsigned int v) { if (v > 0) putbinary(v / 2); putc('0' + (v & 1)); Quote: } /* untested */

Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> USE worldnet address!

Sun, 05 Jun 2005 01:42:46 GMT 


CBFalcone #3 / 4

decimal to binary
Quote:
> > do you know those cool binary watches which tell you the time in > > binary format? I found one at www.thinkgeek.com, it is called > > "Matrix Binary Watch". Ohhhh I want this watch!!! :) > > To kill time, I decided to exercise reading binary time by > > writing a prog that tells you the time in binary format. > > OK.. I did most of the work, but now I'm stuck, because I don't > > know how to transform decimal into binary numbers... I think it > > would be the easiest if i use an array for the binary numbers, > > and modify the decimal numbers with the >> or << operator... but > > I have no idea, how to accomplish this. Can anyone help me? > putbinary(unsigned int v) > { > if (v > 0) putbinary(v / 2); > putc('0' + (v & 1)); > } /* untested */
Revise that to: #include <stdio.h> void putbinary(unsigned int v) { if (v > 0) putbinary(v / 2); putchar('0' + (v & 1)); Quote: } /* putbinary */
int main(void) { int i; for (i = 0; i < 10; i++) { putbinary(i); putchar('\n'); } return 0; Quote: } /* main */

Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> USE worldnet address!

Sun, 05 Jun 2005 02:54:57 GMT 


jrlat.. #4 / 4

decimal to binary
Quote:
>On Tue, 17 Dec 2002 15:13:30 +0100, in comp.lang.c, "Markus Schroeder"
>>Hi; >>do you know those cool binary watches which tell you the time in binary >>format? I found one at www.thinkgeek.com, it is called "Matrix Binary >>Watch". Ohhhh I want this watch!!! :) >>To kill time, I decided to exercise reading binary time by writing a prog >>that tells you the time in binary format. >>OK.. I did most of the work, but now I'm stuck, because I don't know how to >>transform decimal into binary numbers... I think it would be the easiest if >>i use an array for the binary numbers, and modify the decimal numbers with >>the >> or << operator... but I have no idea, how to accomplish this. >>Can anyone help me? >How about repeatedly dividing by 2, and using the remainder?
This process is called 'radix deflation'.  john R. Latala

Sun, 05 Jun 2005 03:44:57 GMT 


