Java: Convert ASCII binary string into Decimal

Date: 2014-01-25 |

DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)

**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 way to support my work is to like / comment / share for the algorithm and subscribe for future updates.