Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Click on the "I" and the "O". Parent comment
All you have to do is integer division by two and keep the remainder. You don't even need to know the powers of two.
Here's an example with 137.
137 % 2 = 1 68 % 2 = 0 34 % 2 = 0 17 % 2 = 1 8 % 2 = 0 4 % 2 = 0 2 % 2 = 0 1 % 2 = 1
Final result: 10001001
You can use a similar method to convert the fractional part of a float, but with multiplication.
All you have to do is integer division by two and keep the remainder. You don't even need to know the powers of two.
Here's an example with 137.
Now reverse the order and zero extend if necessary.Final result: 10001001
You can use a similar method to convert the fractional part of a float, but with multiplication.