1

mrahmedcomputing

KS3, GCSE, A-Level Computing Resources

Lesson 1. Number Bases


Lesson Objective

  • Be able to define primitive data types.
  • Represent positive integers in binary.
  • Represent positive integers in hexadecimal.
  • Convert positive integers between binary and hexadecimal.

Lesson Notes

Primitive Data Types

A primitive data type is a data type that is provided by a programming language.

All data types are held in binary. Without knowing what the data type is, it is not possible to say what a particular bit pattern represents.

00101000 111110001 01010111 00100100

This could be one integer, 4 integers, a real number, a string, 4 characters,…

or even a sound, a pixel or a tiny piece of a graphic


Number Systems

A numeral system is a writing system for expressing numbers; that is, a mathematical notation for representing numbers of a given set, using digits or other symbols in a consistent manner.

Denary (Decimal) Number System

Decimal (or Denary) has 10 digits (0-9), and can be referred to as "base 10". Numbers are organised in multiples of ten's.

Here are examples of Base 10 numbers:

1000s 100s 10s 1s
0 0 0 6
0 1 5 8
3 4 2 3

Binary Number System

Binary has two digits 0 and 1, and is referred to as base 2.

  • Binary is the language computers understand.
  • Computers only work with values of 1 and 0.
  • The reason for this is computers work on circuit boards where there is either high voltage (1) or low voltage (0).

Binary uses only 2 digits, 1 and 0 and each place value goes up in multiples of 2 instead of 10, like the decimal system.

Here are examples of Base 2 numbers:

128 64 32 16 8 4 2 1
0 1 1 0 1 0 1 1
0 1 1 0 1 0 1 1
0 0 1 1 1 0 0 1
0 1 1 0 1 0 1 1
0 1 1 0 1 0 1 1
0 1 1 0 1 0 1 1
0 1 1 0 1 0 1 1

The row highlighted blue shows the Base 10 number 57.

(128*0)+(64*0)+(32*1)+(16*1)+(8*1)+(4*0)+(2*0)+(1*1) = 57.

This shows that 32 + 16 + 8 + 1 = 57.

We don't include the 128, 64, 4 or 2 as they have 0's in their place values.


What is Hexadecimal?

Hexadecimal (or hex) is a base 16 system used to simplify how binary is represented. A hex digit can be any of the following 16 digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F.

Each hex digit reflects a 4-bit binary sequence.

Why use Hexadecimal?

By using hexadecimal, an 8-bit binary number can be written using only two different digits - one hex digit for each nibble (or group of 4-bits). It is much easier to write numbers as hex than to write them as binary numbers. For example:

  • 11010100 in binary would be D4 in hex.
  • FFFF3 in hex would be 11111111111111110011 in binary.

Binary, Denary, Hex:

Binary Decimal Hexadecimal
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 8 8
1001 9 9
1010 10 A
1011 11 B
1100 12 C
1101 13 D
1110 14 E
1111 15 F

Hexadecimal Conversion Examples

Example 1.

Hexadecimal Conversion Examples

Example 2.


Using Hexadecimal

Compact Representation of Binary Data

Hexadecimal simplifies the representation of large binary numbers using fewer digits. It is commonly used for memory addresses, machine code instructions, and other hardware-related values in computing .

Color Representation

In graphics and web design, colors are often specified using hexadecimal notation. Each color component (red, green, and blue) is represented by a two-digit hexadecimal value (ranging from 00 to FF). For example, #FF0000 corresponds to pure red. Hexadecimal makes it easier to define and manipulate colors .

MAC Addresses

Media Access Control (MAC) addresses, which uniquely identify network devices, are typically written in hexadecimal. These addresses play a crucial role in networking and communication between devices. Here is an example of a MAC Address - 4A:32:BE:5D:A4:4F. The MAC address is usually 48 bits long

Debugging and Error Messages

When debugging software, hexadecimal values are commonly used to inspect memory dumps, analyze program execution, and diagnose issues. Hexadecimal provides a more human-readable format for examining binary data.

IP Addresses

Although decimal notation is more common for IP addresses, hexadecimal representation is occasionally used for both IPv4 and IPv6 addresses in specific contexts.

Hexadecimal simplifies binary data representation, aids in color coding, and is essential in various aspects of computer science and programming.


3