tags:

views:

76

answers:

4

As the title says, how do you do that?

A: 
  1. 1387 can be represented on a 16 bit machine, so it's just 1387
  2. 1387.to_s(16) if you're looking for a base 16 representation
  3. 16^2 * d2 + 16^1 * d1 + 16^0 * d0 where d0 : {0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f}
Ben Taitelbaum
A: 
  1. Divide the "desired" base (in this case base 2) INTO the number you are trying to convert.

  2. Write the quotient (the answer) with a remainder like you did in elementary school.

  3. Repeat this division process using the whole number from the previous quotient (the number in front of the remainder).

  4. Continue repeating this division until the number in front of the remainder is only zero.

  5. The answer is the remainders read from the bottom up.

For this reason, base 16, which can have six 2-digit remainders (10, 11, 12, 13, 14, 15) replaces these values with alphabetic representations (10-A, 11-B, 12-C, 13-D, 14-E, 15-F)

Sudantha
+1  A: 

do you know how to do it by hand too?

1387 / 2 is 693, remainder = 1, so you write "1" on paper (or think of it as, when number is not divisible by 2, then write down a 1)

693 / 2 is 346, remainder = 1, so you write another "1", to the left of the digit you write down previously.

And you keep going, and you will get

10101101011

動靜能量
A: 

Depends... It's not about how you represent 1387 in 16 Bit, it's about how you read it back...

erdogany