From: bena [mailto:[EMAIL PROTECTED]

>how to convert decimal to binary using c library

I assume you mean "how do you print a number in binary"?

Well in the spirit of not doing too much of others' homework...

$ type test.c
#include <stdio.h>
#define Show(a) printf("\n" #a " = 0b");pb(a);

void pb(unsigned long ul)??<
    if (ul>1)??<
        pb(ul>>1);
        printf("%d", ul%2?1:0);
    ??>else
    printf("%d", ul?1:0);
??>

int main(void)??<
    Show(0);
    Show(1);
    Show(16);
    Show(15);
    Show(32767);
    Show(0777);
    Show(0xDeadBeef);
    return 0;
??>


$ testc

0 = 0b0
1 = 0b1
16 = 0b10000
15 = 0b1111
32767 = 0b111111111111111
0777 = 0b111111111
0xDeadBeef = 0b11011110101011011011111011101111
$


--
PJH

"During my service in the United States Congress, I took the initiative
in creating the Internet."
    - Al Gore







Alderley plc, Arnolds Field Estate, The Downs, Wickwar, Gloucestershire, GL12 8JD, UK
Tel: +44(0)1454 294556 Fax: +44 (0)1454 299272

Website : www.alderley.com  Sales : [EMAIL PROTECTED] Service : [EMAIL PROTECTED]

This email and its contents are confidential and are solely for the use of the intended recipient. If you are not the original recipient you have received it in error and any use, dissemination, forwarding, printing or copying of this email is strictly prohibited. Should you receive this email in error please immediately notify [EMAIL PROTECTED]

This email has been scanned for viruses, however you should always scan emails with your own systems prior to opening.






To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.


Yahoo! Groups Sponsor
ADVERTISEMENT
click here


Yahoo! Groups Links

Reply via email to