Inbuilt decimal to binary conversion function in C++

Discussion in 'C++' started by Raja, Jun 16, 2004.

  1. Raja

    Raja Guest

    IS there any inbuilt decimal to binary conversion function in C++
     
    Raja, Jun 16, 2004
    #1
    1. Advertising

  2. Raja

    Sharad Kala Guest

    "Raja" <> wrote in message
    news:...
    > IS there any inbuilt decimal to binary conversion function in C++


    I think you mean to get binary representation of a given int.

    cout << bistset<10>(7); // 7 in binary with 10 bits

    -Sharad
     
    Sharad Kala, Jun 16, 2004
    #2
    1. Advertising

  3. Raja

    JKop Guest

    Raja posted:

    > IS there any inbuilt decimal to binary conversion function in C++



    Well... all computers store data in binary.

    As such I pressume you're talking about strings, ie.


    "23" -> "00010111"


    Maybe something along the lines of:


    #include <stdlib.h>

    int main(void)
    {
    char binary_string[10];

    unsigned short int number = 23;

    itoa(number,binary_string,2);

    //The 2 in the above specifies the radix, ie. the number of digits
    //in the number system. For decimal, this would be 10. For, octal, 8.
    //For Hexadecimal, 16. For binary, 2.

    }



    -JKop
     
    JKop, Jun 17, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. km

    inbuilt function buffer()

    km, Jan 20, 2005, in forum: Python
    Replies:
    0
    Views:
    386
  2. ragav

    Print without using any inbuilt function?

    ragav, Dec 8, 2006, in forum: C Programming
    Replies:
    13
    Views:
    2,088
  3. Ven
    Replies:
    3
    Views:
    1,352
  4. Replies:
    5
    Views:
    151
    Mirco Wahab
    Aug 20, 2007
  5. kaushal
    Replies:
    3
    Views:
    214
    Dr J R Stockton
    Aug 11, 2008
Loading...

Share This Page