Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten...

23
Hexadecimal number system

Transcript of Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten...

Page 1: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Hexadecimal number system

Page 2: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Decimal System• The Decimal System is a Base 10 system.

• That simply means it uses 10 symbols:

0 1 2 3 4 5 6 7 8 9

• Each digit can be used any number of times

•Value of a digit is determined by its position

•6 2 4 in base 10 positional notation is:

600 + 20 + 4

6 hundreds + 2 tens + 4units

6 x 102 + 2 x 101 + 4x 100

Page 3: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Recap: Binary Number System

• The Binary System is a Base 2 number system

• It only uses 2 symbols. (0 and 1)

• Each digit can be used any number of times

• Each digit’s value is determined by its position

• 1 0 1 in base 2 positional notation is:

100 + 0 + 1 i.e.

1 x 22 + 0 x 21 + 1 x 20

Page 4: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Hexadecimal Number System

• Hex means six ; decimal means ten

• Hence Hexadecimal means 6 and 10 i.e. 16

• Decimal (Base 10) uses 10 digits

• Binary (Base 2) uses 2 digits

• Hence Hexadecimal (Base 16) will use ___ digits

• Which digits will be used for base 16 :

0 1 2 3 4 5 6 7 8 9 ? ? ? ? ? ?

16

Remember we will need 16 digits

Page 5: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Hexadecimal Number System• Hexadecimal system (Base 16) will have 16 digits

• But we have only 10 digits (0 1 2 3 4 5 6 7 8 9)

• How can we represent the 11th 12th 13th 14th and 15th digit?

• We cannot use digits 0 1 2 3 ….. Again

• Need to use 16 different ‘values’ to represent each digit

• Which distinct symbols to use for 10 and above ???

• We will use alphabetical characters A B C D E F

• So the 16 digits will be :

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

Page 6: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Hexadecimal Number System

Decimal Binary (4 bit) Hexadecimal0 0000 01 0001 12 0010 23 0011 34 0100 45 0101 56 0110 67 0111 78 1000 89 1001 9

10 1010 A11 1011 B12 1100 C13 1101 D14 1110 E15 1111 F

Page 7: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Reason for choosing hexadecimal to represent numbers

1. It is can be used to represent binary code in a format easier for

humans to read and write.

• Enables very large numbers to be written using fewer characters

• By representing a group of 4 binary bits (a nibble) by only one hex

digit.

• 8-bits (1 byte) need just 2 HEX digits.

• 16-bit binary numbers need only 4 HEX digits.

• It takes up less place on the screen or page.

Page 8: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Reason for choosing hexadecimal to represent numbers

2.It is fast and easy to convert the Hex

representation back into the actual Binary

•Using a process simple enough to be done in your

own mind

•E.g. F A 1 7 hex is

_______________________ in binary1111 1010 0001 0111

Page 9: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Uses of hexadecimal numbers in computing

Usage 1: Media access control address - MAC address

•A unique number assigned to a device on a network / internet

• Two devices on a network cannot have the same MAC address

•MAC addresses are assigned by the manufacturer of the

network device

•It is stored in the ROM (read-only memory) of the device

Page 10: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Format of a MAC address

•A MAC address consists of six pairs of hexadecimal digits

•Each pair is separated by colons or dashes :

1A : 16 : C5 : 22 : FF : FF (using colons) Or

1A – 16 – C5 – 22 – FF – FF (using dashes)

• The MAC address is assigned by the manufacturer of the network device

•It is stored in the ROM (Read Only Memory) of the device

•Two devices on a network will never have the same MAC address

Page 11: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Format of a MAC address

•A MAC address has 6 pairs of hex digits• What do the digits represent?

•First 3 pairs identify the company that manufactured the device

•Last 3 pairs are specific to the device (i.e. the serial number of

the device)

•Together, the two parts of the MAC address form an ID that is

unique to a device.

Page 12: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Use/Importance of MAC addressWhy are MAC addresses used?

•To uniquely identify a computer on a network / internet

What is the importance of MAC Addresses?

•To distinguish one device (computer/smartphone...) from

another on a network / internet.

•Internet users can post using anonymous or fake names but they

cannot hide their MAC address. Hence they can be traced back.

Page 13: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Uses of hexadecimal numbers in computing

Usage 2: In machine code and assembly language

Review compiler/interpreter/assembler (Done in Grade 10)

•Machine code is instructions in binary (1's and 0's)

• Example of machine code (Binary) instruction

101101000000000010110000000100111100110100010000

•Machine code can be executed directly by the CPU

• Fast because there is no need for translation

• But Very difficult / time consuming for human to write / to understand /to debug.

Page 14: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Recap: Assembly language

Assembly code is plain-text and human readable code

•This is done using mnemonics (abbreviations) for the actual machine

code instructions

•Examples of mnemonics:

• jmp (jump)

•sto (store)

• lda (load)

•cmp (compare)

Ex: Assembly code to compare two numbers

MOV AX,DATA

MOV DS,AX

LEA SI,ARR

MOV AL,ARR[SI]

MOV LARGE,AL

MOV CX,LEN

CMP LARGE,AL

JG NOCHANGE

MOV LARGE,AL

No need to remember the assembly code

Page 15: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Hexadecimal in machine code and assembly language

•Hexadecimal allows a group of 4-bits to be converted

into a single digit. Hence

•It speeds up the coding (program writing) process

•Code (program) is much easier to read, understand

and write

•Saves memory space.

But we should not forget that the computer does NOT understand hexadecimal.A converter (Hexadecimal to Binary and Binary to Hexadecimal) is used when the program is being executed.

Page 16: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Uses of hexadecimal numbers in computing

Usage 3: Debugging memory dumps• A memory dump is the contents of computer memory at a specific time

• Generally when the program has crashed or giving abnormal results.

• Debugging means to analyse the memory dump to detect errors that is

causing the crash or abnormality

• Debugging becomes easier to debug if the memory dump is displayed in

hex instead of binary.

• WHY? Because it takes less space / easier to read and understand

Page 17: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Uses of hexadecimal numbers in computing

Usage 4: For Defining colours in HTML

•HTML = Hypertext Markup Language

• It is a language used when writing and creating web pages

• It is NOT a programming language.

Page 18: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Defining colours in HTML

•HTML specifies how things will look like on a web page

using HTML tags

•HTML Tag starts with < > ends with </>

•For example:

<p> Some text </p> a normal paragraph

<b> text </b> text is shown in bold

Page 19: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Defining colours in HTML

•But how to specify colour of the text in HTML document?

•Computers can use millions of colours

•Can we give a name to each colour?

• A colour is formed by the combination of 3 primary colours:

• Red, Green and Blue (RGB)

• Combining RGB in various intensities we can create millions of

colours

Page 20: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Defining colours in HTML

• HTML specifies colour of text using 3 pairs of Hexadecimal digits,

one pair for each colour:

• First pair represents the intensity of RED

• Second pair represents intensity of GREEN

• Third pair represents the intensity of BLUE

• Each pair can take any value between 00 and FF (in decimal:between 0 and 255)

• Hexadecimal colour codes are made by mixing the colours of R, G, and

B (in that exact order).

Page 21: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Defining colours in HTML • For RED

• <font color “ # F F 0 0 0 0 “ > </font>

• For GREEN:

• <font color “ # 0 0 F F 0 0“ > </font>

• For BLUE:

• <font color “ # 0 0 0 0 F F“ > </font>

• Combination of RGB can give millions of colours.

R G B

R G B

R G B

What will be the colour code for BLACK?

What will be the colour code for WHITE?

Page 22: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

Workout Past Exam Paper

Nov 2015 paper 12 Question 4

(click to download)

Homework

Computer Science Workbook:

P5 Q 6 - 8

P10 Q 12-13

P12 Q 16

Page 23: Hexadecimal number system€¦ · Hexadecimal Number . System •Hex means six ; decimal means ten •Hence Hexadecimal means 6 and 10 i.e. 16 •Decimal (Base 10) uses 10 digits

END Hexadecimal