Contact Us

Scripts: Cplus :: C++ string functions :: Library Article #3

Developer's Section

Convert an Integer to a Binary Number in C++
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (1601)

Code to convert an Integer to a String representing a Binary Numner.

This article shows how to convert any integer number to a string representing its corresponding binary value:

 Code Snippet 1

//method: convert to binary (unsigned) 
string to_binary(int thisValue) 
    string answer;

    int comm = 0;

    while( thisValue != 0 )
        comm = (thisValue % 2);

        if(comm == 0)
            answer = "0" + answer;

        if(comm == 1)
            answer = "1" + answer;

        thisValue = (thisValue / 2);
    return answer;

See other Scripts in C++ string functions

Submit Your Scripts:

System Message:
  • Your C++ script has been sent. Please allow 48 hours for processing.

If you would like to have your C++ scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]