#include <iostream>
#include <string>
std::string convertTobinary(long num)
{
std::string binaryVal = "";
if(num == 0) return "0";
while(num != 0)
{
if(num %2 == 0)
binaryVal = "0" + binaryVal;
else
binaryVal = "1" + binaryVal;
num /= 2;
}
return binaryVal;
}
int main(int argc, char **argv)
{
std::cout<<"\n binaryVal : "<<convertTobinary(100);
return 0;
}
No comments :
Post a Comment