News for hackers. Stuff that matters.
Re:Click on the "I" and the "O" by pygy_ on Thursday May 09, 2013 @09:44AM (#5680383)
Decoding is easy with pen and paper, if not mentally. You must know your powers of two. In the order that concerns us:

128, 64, 32, 16, 8, 4, 2, 1

----

Let's decompose 231.

----

231 >= 128; That's a 1 in first position. 1

231 - 128 = 103 >= 64; We have a one in the second position. 11.

103 - 64 = 39 >= 32; One in the third position. 111.

39 - 32 = 7 < 16; Zero in the fourth position. 1110.

7 < 8; Zero in the fifth place. 11100

7 >= 4; 111001

7 - 4 = 3 >= 2; 1110011

3 - 2 = 1 >= 1; Final result: 11100111. Enjoy your cats :)

Re:Click on the "I" and the "O" by zerohp on Thursday May 09, 2013 @10:23AM (#5680558)
That method is what I did until I went back to school for computer engineering.

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
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.

Re:Click on the "I" and the "O" by pygy_ on Thursday May 09, 2013 @12:22PM (#5681247)
Neat, thanks for the tip :)