# Lab 4: 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.) If you haven't done so (but even if you have!) 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 representation, 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?