i'm the beginner of C++...i was try to convert binary to decimal..but it's not easy....i converted decimal to binary but i have no idea about binary to decimal....please help me....please....
: i'm the beginner of C++...i was try to convert binary to decimal..but it's not easy....i converted decimal to binary but i have no idea about binary to decimal....please help me....please....
Hey there,
I'm not going to give you the source for it, but I'll explain the easiest way to go about doing it.
You're going to have to split up each digit of the binary number and put them in either seperate variables or in an array. Then, simply multiply each digit by its value (i.e. 1, 2, 4, 8, 16, 32, 64, 128...) and store THOSE values into either seperate variables or in an array. Then, add those together and viola! instant decimal.
: i'm the beginner of C++...i was try to convert binary to decimal..but it's not easy....i converted decimal to binary but i have no idea about binary to decimal....please help me....please....
I think that I have an easier way then the posted message that is here... instead of putting all of the numbers from an array into their own variables and creating millions of variables(because you have to supply enough for binary numbers longer then 10 digits). The way that I did it(I have a class and it was an assignment) was I asked the user for the binary number. Place the number the user gives into a char array. After that reverse the string. Create a do while loop that takes the takes the first number checks to see if it is a one or a zero (hint:modulus operator) and then check the place of the number, then if it is a 1 raise two to the power of the place (don't forget that the first place is actually place zero) and continue that while loop until the length of the loop
Comments
Hey there,
I'm not going to give you the source for it, but I'll explain the easiest way to go about doing it.
You're going to have to split up each digit of the binary number and put them in either seperate variables or in an array. Then, simply multiply each digit by its value (i.e. 1, 2, 4, 8, 16, 32, 64, 128...) and store THOSE values into either seperate variables or in an array. Then, add those together and viola! instant decimal.
I think that I have an easier way then the posted message that is here... instead of putting all of the numbers from an array into their own variables and creating millions of variables(because you have to supply enough for binary numbers longer then 10 digits). The way that I did it(I have a class and it was an assignment) was I asked the user for the binary number. Place the number the user gives into a char array. After that reverse the string. Create a do while loop that takes the takes the first number checks to see if it is a one or a zero (hint:modulus operator) and then check the place of the number, then if it is a 1 raise two to the power of the place (don't forget that the first place is actually place zero) and continue that while loop until the length of the loop