As the title says, how do you do that?
- 1387 can be represented on a 16 bit machine, so it's just 1387
1387.to_s(16)
if you're looking for a base 16 representation- 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}
Divide the "desired" base (in this case base 2) INTO the number you are trying to convert.
Write the quotient (the answer) with a remainder like you did in elementary school.
Repeat this division process using the whole number from the previous quotient (the number in front of the remainder).
Continue repeating this division until the number in front of the remainder is only zero.
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)
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
Depends... It's not about how you represent 1387 in 16 Bit, it's about how you read it back...