The binary numeral system (base 2 numerals) represents numeric values using two symbols: 0 and 1.
Counting in binary is similar to counting in any other number system.
If you want to increase a number by 1, try to increase its last digit by 1.
If this fails, set the last digit to zero, and try to increase the previous digit,
and so on, until you succeed.
For example, the decimal sequence:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...
converted to binary looks as follows:
1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, ...
You are given a String x that contains the binary representation of a positive integer X.
Write a method that will return a String containing the binary representation of (X+1).
The returned String must not contain leading zeroes.
|