#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# binary to decimal convertion...

Member Posts: 7
i would like to ask for a help regarding binary to decimal convertion in C++ programming. If possible, the convertion should include float numbering. ex (0.53).... If this can be done, please send me some examples with sourse code... E-mail: steven_cth@yahoo.com ... thank you for anticipation...

• Member Posts: 6
: i would like to ask for a help regarding binary to decimal convertion in C++ programming. If possible, the convertion should include float numbering. ex (0.53).... If this can be done, please send me some examples with sourse code... E-mail: steven_cth@yahoo.com ... thank you for anticipation...
:
:

Offhand, I can see two major ways to do this, but I'll present what I think might be the better. In both cases, I assume you have the binary number in a string of some sort (string, char[x], etc)

Before the radex point (the decimal point is a special case of a radex point for base 10) the algorithm involves starting an accumilator at 0.
Until you hit the radex point , multiply the accumilator by 2, and then add the value of the next character.

Thus, 100110 becomes
x x x x x x
2(2(2(2(2(2(0)+1)+0)+0)+1)+1)+0 => 40
(I have marked the parts of the original number with x's)

(Multiplying and adding can be substituted with shift and or operations)

When dealing with places after the decimal point, proceed as if there were no radex point. But, count the number of places after the radex point. When the end of the string is reached, divide the total by 2 to the power of the number of spaces.

Thus
1.11 (1.75 in decimal) is 2(2(2(2(0)+1)+1)+1) = 7. Two places after the radex point, so divide by 2^2, or 4.
7/4 = 1.75

And
11 (3 in decimal) is (2(0)+1)+1 = 3. Zero places after the point, becoming 3/(2^0), or 3/1 = 3.

Thanks for the problem. It was interesting. I hope my solution works for you. I'll leave the coding to you, but if you have a specific problem, repost.

• Member Posts: 7
: : i would like to ask for a help regarding binary to decimal convertion in C++ programming. If possible, the convertion should include float numbering. ex (0.53).... If this can be done, please send me some examples with sourse code... E-mail: steven_cth@yahoo.com ... thank you for anticipation...
: :
: :
:
: Offhand, I can see two major ways to do this, but I'll present what I think might be the better. In both cases, I assume you have the binary number in a string of some sort (string, char[x], etc)
:
: Before the radex point (the decimal point is a special case of a radex point for base 10) the algorithm involves starting an accumilator at 0.
: Until you hit the radex point , multiply the accumilator by 2, and then add the value of the next character.
:
: Thus, 100110 becomes
: x x x x x x
: 2(2(2(2(2(2(0)+1)+0)+0)+1)+1)+0 => 40
: (I have marked the parts of the original number with x's)
:
: (Multiplying and adding can be substituted with shift and or operations)
:
: When dealing with places after the decimal point, proceed as if there were no radex point. But, count the number of places after the radex point. When the end of the string is reached, divide the total by 2 to the power of the number of spaces.
:
: Thus
: 1.11 (1.75 in decimal) is 2(2(2(2(0)+1)+1)+1) = 7. Two places after the radex point, so divide by 2^2, or 4.
: 7/4 = 1.75
:
: And
: 11 (3 in decimal) is (2(0)+1)+1 = 3. Zero places after the point, becoming 3/(2^0), or 3/1 = 3.
:
: Thanks for the problem. It was interesting. I hope my solution works for you. I'll leave the coding to you, but if you have a specific problem, repost.
:
:
Thank you for your help. Please post some example program here, so that i can understand and see how the program work. Again thank you a lot.
• USAMember Posts: 0

_____ | http://forcoder.org | free ebooks and video tutorials about / C Visual Basic .NET Perl Swift Java Scratch C++ Assembly JavaScript PHP MATLAB Ruby PL/SQL Python Go C# Objective-C Delphi Visual Basic R D Scheme ML Dart FoxPro Bash LabVIEW Clojure Lua Ada COBOL Awk ABAP VBScript Erlang F# Kotlin Prolog Logo Fortran Alice Julia Rust Crystal Transact-SQL Lisp SAS Apex Scala Hack / ___________