decimal to binary 
Author Message
 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  
 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  
 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  
 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  
 
 [ 4 post ] 

 Relevant Pages 

1. decimal to binary

2. how to convert numbers in decimal to binary?

3. decimal to binary helps

4. decimal to binary, hex, octal?

5. converting decimal to binary

6. Decimal to binary

7. decimal to binary - le.c [1/1]

8. C Code for decimal to binary conversion

9. decimal to binary number C routines

10. Hex to Decimal or Binary and Vice Versa

11. Need Decimal to Binary converter....

12. Convert from binary to decimal, hex to decimal etc

 

 
Powered by phpBB® Forum Software