You are on page 1of 5

Binary-Hexadecimal Worksheet 1

Hexadecimal is base-16 (16=24 digits so 4 bits per digit)

 Our ten decimal digits aren't enough, so we add 6 new ones:


0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

 0110-0101-1000-1011-0000-1101b =658B0Dh

 Because we constantly slip between binary and hex, we have a


special marker for it

 Prefix with '0x' (zero-x). So 0x658B0D=6654733d , 0x123=291d


Binary-Hexadecimal Worksheet 2

Quick summary

0100 1101 0110 1011 1000 0011 0000 1111


4 D 6 B 8 3 0 F
◆ All microprocessor instructions are represented in hexadecimal
◆ Convert from decimal to hexadecimal is the same as converting to binary, except, divide by 16
instead of 2:
16 237
14 r 13

Answer: E D h

From Binary to Hexadecimal


Starting at the binary point and working left, separate the bits into
groups of four and replace each group with the corresponding
hexadecimal digit.

100010112 = 1000 1011 = 8B16

From Octal to Binary


Replace each octal digit with the corresponding 3-bit binary string.
2138 = 010 001 011 = 100010112

From Hexadecimal to Binary


Replace each hexadecimal digit with the corresponding 4-bit binary
string.
Binary-Hexadecimal Worksheet 3

8B16 = 1000 1011 = 100010112

Conversions: Hexadecimal  Binary  Decimal


There are two ways to convert between Base 16 or Base 8 … and Decimal.

Method 1: Convert to Binary, then Decimal:

0x1af = 0001 1010 1111

= 28 + 2 7 + 25 + 23 + 22 + 21 + 20

= 256 + 128 + 32 + 8 + 4 + 2 + 1

= 43110

0x456 = 0100 0101 0110 = 210+26+24+22+21 = 1024 + 64 + 16 + 4 + 2 = 111010

Method 2: Use division remainders:

Convert from base 10 to base N (Example base 2):

Number / 2 -> remainder is digit0

-> quotient / 2 -> remainder is digit1

-> quotient / 2 -> remainder is digit2


Binary-Hexadecimal Worksheet 4

Example 1: Convert 3610 into binary:

Quotient/2 ->Remainder

36/2 ->0

18/2 ->0

9/2 ->1

4/2 ->0

2/2 ->0

1/2 ->1

3610 = 1001002

Example 2: Convert 3610 into base 16:

36/16 ->4

2/16 ->2

3610 = 2416

Example 3: Convert 0x1af to base 10:

0x1af = 1 x 162 = = 256

a x 16 = 10 x 16 = 160

f = +15

Total = 43110

Now you try some conversions between base 16 and base 10 (Your choice of method!)

0x AC4= 0x C4A=

4310= 16210=
Binary-Hexadecimal Worksheet 5

More Examples

Example 1: What is 4B5 (Hexadecimal)?

 The "4" is in the "16×16" position, so that means 4 ×16×16


 The "B" (11) is in the "16" position, so that means 11 ×16
 The "5" is in the "1" position so that means 5.
 Answer: 4B5 = 4×16×16 + 11×16 + 5 (=1205) in Decimal

You might also like