1. ## Displaying Binary Numbers

Does anyone know how to display the binary number system in the output of a program?

Any help would be greatly appreciated.

2. Did you try searching the forum first? This is a fairly common question.

3. If you happen to have any code that would be great. As Prelude suggested there are numerous ways to show binary data, you will just need to search for those and apply the ones that are best suited for your application, be it a binary data file or convertion to binary and back.

4. Code:
```  #include <stdio.h>
int main(){
int i, val = 1;
for(i = 1, i < 35, ++i){
printf("%15d%15u%15x%15o\n", val, val, val, val);
val *= 2;
}
return 0;
}```
This is what my assignment is, but I would like to go the extra mile and incorporate the binary display if I do an incremental val count in the loop

5. Newbie: "How do I print a number in binary?"
Guru: "Search the forum, this is a common question."
Newbie: "I want to print a number in binary."
Guru: "Search the forum, this has been asked before."
Newbie: "So how can I print a number in binary?"
Guru: "Search the freaking forum already!"
Newbie: "What about printing a number in binary?"

* Guru beats Newbie to death with a blunt object *

6. Well your for loop needs to use ; and not a comma separator. Also your fourth val value in your printf statement should be renamed, and thus should be the output from another function that converts your decimal to binary, perhaps using a pointer to char to store your ones and zeros.

What I mean is that you will need to call another function from within your for loop that will convert your 'val' value to binary. You will need to pass this value( in decimal if you like) and assign the output(char*) from this new conversion function to another value, call it binary.

example

Code:
```:
printf("%15d%15u%15x%15s\n", val, val, val, binary);
val *= 2
dec_to_bin(val);
}
return 0;
}

char * dec_to_bin(int value)
{
char * value;
:
:

return value;
}```
As noted there are many functions out there and many ways to accomplish this. But this should get you going.

7. Sorry, you will need to define binary. Suggest

Code:
`char * binary;`
Then

Code:
`binary = dec_to_binary(int val);  /* example only */`

8. thank you

9. Originally Posted by Prelude
Did you try searching the forum first? This is a fairly common question.
Yes I searched first, and what I was looking for wasn't listed

10. >Yes I searched first, and what I was looking for wasn't listed
Ooh, that's such a lie. I've personally answered this question countless times, so you can't get away with telling me it's not there.