Java: Convert ASCII binary string into Decimal

Date: 2014-01-25 |

**Objective: **Convert a string of ASCII binary values into decimal value in integer data type.

Here’s the solution I concocted:

(https://gist.github.com/SIRHAMY/8626697)

**Logic: **Starting from the beginning of the string, we check to see if the ASCII character is equal to 1.  If it is, we determine how much value that one represents by updating the scalar to 2^(positions to the right of the character) then adding it to the result.  If the character happens to be the last character in the string, then we simply add one to the pending result.

Want more like this?

The best / easiest way to support my work is by subscribing for future updates and sharing with your network.