Module 4: Part II

Number Systems

Converting from Decimal to Binary

  • Take the original value and divide by 2

    • Continue dividing each quotient by 2 until you end up with 0.5

    • Remainder of each division by 2 is the bit that goes in the 0, 1, 2, 3 place and so on

  • Ex:

    • Convert 13 to binary

    • 13/2 = 6 with remainder of 1 (1 in zero place)

    • 6/2 = 3 with remainder of 0 (0 in ones place)

    • 3/2 = 1 with remainder of 1 (1 in twos place)

    • ½ = 0 with remainder of 1 (1 in threes place)

    • 13 in binary is 1101

  • Ex 2:

    • Convert 422 to binary

    • 422/2 = 211 remainder 0 (zeros place)

    • 211/2 = 105 remainder 1

    • 105/2 = 52 remainder 1 

    • 52/2 = 26 remainder 0 

    • 26/2 = 13 remainder 0 

    • 13/2 = 6 remainder 1 

    • 6/2 = 3 remainder 0

    • 3/2 = 1 remainder 1

    • ½ = 0 remainder 1

    • 422 in binary = 0b110100110

Converting from Decimal to Hexdecimal

  • How many times does a power of 16 fit into our value?

  • 16^0 = 1, 16^1 = 16, 16^2 = 256, 16^3 = 4096, 16^4 = 65536, 16^5 = 1038577 and so on…

  • Ex: Convert 9742 from decimal to hexadecimal

    • start with the largest multiple of 16 that can fit into our original numbers

    • How many times can 4096 fit into 9742? Two times

      • So, the fourth value in our answer is 2 (working from left to right)

      • 4096 contributes to our overall value twice

      • 9742 - 4096(2) = 1550

    • Then, we move down the powers of 16 

    • How many times can 256 fit into 1550? Six times

      • So, the third value in our answer is 6 (working from left to right)

      • 1550 - 256(6) = 14

    • Then, we move down the powers of 16 

    • How many times can 16 fit into 14? Zero times

      • So, the second value in our answer is 0 (working from left to right)

      • No subtraction since 16 did not contribute to our total value

    • Then, we move down the powers of 16 

    • How many times can 1 fit into 14? 14 times

      • So, the first value in our answer is E (in hexadecimal) (working from left to right)

      • Final answer: 9742 in hexadecimal = 0x260E

robot