1. binary based output

hello,

Is there any simple way to show output in bin base.

something like....

Code:
```int digit = 10;
printf("%s",DecToBin(digit));```
expected output:
1010

I use gcc.

2. Depends what you mean by simple. For converting an unsigned datatype to binary you could just use bit-shifting to find each individual bit in the variable and stick them in a string of characters.
Code:
```void convertToString(unsigned long input, char* output)
{
int i;
for(i = 0; i < 32; i++) //assuming unsigned long is 32 bits. Don't shoot me, Prelude! :D
{
output[i] = input & (1 << (31 - i)) ? '1' : '0';
}
}```
Something to that effect. I didn't test it, so it might not work entirely properly, but that's the gist of it.

**EDIT**
Note: Assuming that an unsigned long is 32 bits is bad programming practice

3. >Is there any simple way to show output in bin base.
Sure. So simple that it can be done in one line.
Code:
```#include <stdio.h>

int dtob ( int d )
{
return d ? dtob ( d >> 1U ), putchar ( d & 1U | '0' ) : 0;
}

int main ( void )
{
dtob ( 10 );

return 0;
}```
>//assuming unsigned long is 32 bits. Don't shoot me, Prelude!
Just as long as you mention that it's a bad practice somewhere in your post.

4. >>Sure. So simple that it can be done in one line.
Woh. So... you wanna comment that line?

>>Just as long as you mention that it's a bad practice somewhere in your post.
Done.

5. I see what that function does.. but what is the U for?

btw, wonderful use of the ternary operator and recursion.. very impressive.

Ok, I also got lost when you or it with '0'.. isnt that 0x30 hex?
hmmmmmmmmmmmmmm.

6. Code:
`putchar ( d & 1U | '0' )`
...So you get 0x30 or 0x31 ('0' or '1'). You could rewrite it as:
Code:
`putchar ( ( d & 1U ) + '0' )`
...if it makes more sense to you.

The U is for Unsigned (I think).

7. Ok, I now get what the line does. But why does dtob have to return a value?

8. So it knows when to stop recursing?

Is recursing a real word?

9. Is recursing a real word?
probably not

10. >>So it knows when to stop recursing?
No, it knows that when d == 0...

11. Yeah, it returns 0 and quits the function, else it calls it self again (recurses).

I think she did that to show it could be done in one line.

12. Code:
```void dtob ( int d )
{
d ? dtob ( d >> 1U ), putchar ( d & 1U | '0' ) : 0;  //I think that works...
}
void dtob ( int d )
{
if(d) dtob ( d >> 1U ), putchar ( d & 1U | '0');  //I think that works...
}
void dtob ( int d )
{
int dummy = d ? dtob ( d >> 1U ), putchar ( d & 1U | '0' ) : 0;  //That works
}```

13. Ah I see... then um.. I dunno.

I'm sure there is a reason behind it since it's Prelude. Probably some kind of "good habit" lesson in there somewhere.

14. >>Probably some kind of "good habit" lesson in there somewhere.
I suppose so, even in writing code that breaks just about every readability rule there is Prelude will stick to her good habits

15. thank you all,