Viewing a single comment thread. View all comments

Minyguy t1_j6h2ogs wrote

I don't know the exact answer youre looking for, but there is definetly a way to convert decimal to binary.

Use a loop that compares the number with increasingly larger powers of two.

Find the power of two that is just below (or equal)

So for 103, the power of two just below would be 64. Aka 2⁶

So then we know that in binary it is a six-digit number.

If the number is equal or larger than 2⁶ subtract 2⁶ and note a '1', otherwise note a '0'

Then repeat in descending order for 2⁶, 2⁵, 2⁴, 2³, 2², 2¹, 2⁰

>= Means greater than or equal to

!>= Means not greater than or equal to

103 !>= 128 so '0'

103 >= 64 so '1', and 103 - 64= 39

39 >= 32 so '1', and 39 - 32 = 7

7 !>= 16 so '0'

7 !>= 8 so '0'

7 >= 4 so '1' and 7 - 4 = 3

3 >= 2 so '1' and 3 - 2 = 1

1 >= 1 so '1' and we are done.

Unless I made a mistake, 103 in binary should be 01100111, you also could cut off the extra 0 and just say 1100111.

1