Value to binary number.

This is a discussion on Value to binary number. within the General Discussions forums, part of the Community Boards category; When calculating the value of a binary number for example 10010111 I need to do the following. (1*2^7) + (0*2^6) ...

1. Value to binary number.

When calculating the value of a binary number for example 10010111 I need to do the following.
(1*2^7) + (0*2^6) + (0*2^5) + (1*2^4) + (0*2^3) + (1*2^2) + (1*2^1) + (1*2^0) = 128 + 0 + 0 + 16 + 0 + 4 + 2 + 1 = 151
But what if I am given the number 456 and I need to convert this value into a binary number. How would I do this this?

2. Originally Posted by JOZZY& Wakko
But what if I am given the number 456 and I need to convert this value into a binary number.
It's already stored that way. Ironically, there is no standard method for presenting a binary number in human readable output in C -- the way that %d and %x work for decimal and hexadecimal.

So you have to turn int x=456 into a string, "111001000". I'll give you a clue:
Code:
```	int x=456, i;
for (i=512; i>0; i/=2) {```
the next step involves testing with AND (x&i).