# Lab : Numeric Systems: Decimal, Binary, Hexadecimal ; ASCII and Unicode

## Overview

Goal: Becoming familiar with different numeric systems and converting from one to the other.

- Practice with decimal to binary
- Practice with binary to decimal
- Practice with binary to hex
- Practice with hex to binary

## Binary to Decimal

Inside a computer, numbers are represented using the Binary System, as you know. What is special about "binary" to make it suitable for use in digital computers?

Let's write the first 15 decimal numbers with their corresponding binary number next to each one:

0_{2} --> 0_{10}

1_{2} --> 1_{10}

10_{2} --> 2_{10}

11_{2} --> 3_{10}

100_{2} --> 4_{10}

101_{2} --> 5_{10}

110_{2} --> 6_{10}

111_{2} --> 7_{10}

1000_{2} --> 8_{10}

continue up to 15...

### Question 1:

How many numbers can we represent with one bit only? Which ones? How many with two and three bits? How about if we have n bits available?

### Question 2:

How many bits do we need in order to represent the first 15 numbers? How about the first 16, 25 or n numbers?

### Exercise 1:

As a reminder, here is an example of converting a binary number into its equivalent decimal:

Now look at the following binary numbers. How many bytes is each one? Can you guess which of them is the largest one?
Convert the following `binary numbers into decimal`

.

00000000_{2} -->

00001111_{2} -->

01101011_{2} -->

11111111_{2} -->

00000000 00000000_{2} -->

00000000 11111111_{2} -->

00000010 01100011_{2} -->

00000001 01100011_{2} -->

## Decimal to Binary

To convert a decimal number to the binary equivalent, we need to express the decimal number as a sum of powers of 2. (This is a more involving process than what we did going from binary to decimal.) Watch this video, min 3:00 to 5:30:

### Exercise 2:

Convert the following `decimal numbers into binary`

:

10_{10} -->

11_{10} -->

16_{10} -->

19_{10} -->

22_{10} -->

66_{10} -->

130_{10} -->

1000_{10} -->

## Hexadecimal and Binary

So, people are happy with the decimal system, computers are happy with the binary. Why use hexadecimal at all then??

Watch the same video above, from min 5:45 to 7:30 and min 9:00 to 9:40

Computer scientists and engineers use hexadecimal, often times, to communicate among themselves, for example when they talk about memory addresses or colours!

#### Question 3:

List the hex digits and their corresponding decimal value.

#### Exercise 3:

Predict which of the following hex numbers has the highest value, and explain why.
Then, convert the following `hex numbers into binary and decimal`

:

A1_{16} -->

42_{16} -->

3E8_{16} -->

2B_{16} -->

10C_{16} -->

## Text, ASCII and Unicode

### Exercise 4: Write the word:

**Computer**

in ASCII and then in binary and hex.

### Question 4:

What is ASCII? What is Unicode? How are they different?