O Level CS P1 Hexadecimal

O Level CS P1 Hexadecimal

To view other notes of GCSE \ IGCSE Computer Science Click Here.

At the very launch of computer expansion it was realized that people had many complexities in managing binary numbers. For this reason, a new number system using 16 different symbols was developed. The one main disadvantage of binary numbers is that the binary string equivalent of a large decimal base-10 number can be quite long. When working with large digital systems, such as computers, it is common to find binary numbers consisting of 8, 16 and even 32 digits which makes it difficult to both read and write without producing errors especially when working with lots of 16 or 32-bit binary numbers.

One common way of overcoming this problem is to arrange the binary numbers into groups or sets of four bits (4-bits). These groups of 4-bits uses another type of numbering system also commonly used in computer and digital systems called Hexadecimal Numbers.

REPRESENTING INTERGERS AS HEXADECIMAL NUMBERS:

The base 16 notational system for representing real numbers. The digits used to represent numbers using hexadecimal notation are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F.

“H” denotes hex prefix.

Examples:

2816 = 28H = 2 x 161 + 8 x 160 = 40

2F16 = 2FH = 2 x 161 + 15 x 160 = 47

BC1216 = BC12H = 11 x 163 + 12 x 162 + 1 x 161 + 2 x 160 = 48146

Numeric Systems Conversion Table

Decimal Base-10Binary Base-2Octal Base-8Hexadecimal Base-16
0000
1111
21022
31133
410044
510155
611066
711177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F
16100002010
17100012111
18100102212
19100112313
20101002414
21101012514
22101102615
23101112717
24110003018
25110013119
2611010321A
2711011331B
2811100341C
2911101351D
3011110361E
3111111371F
321000004020
 
WHY USE HEXADECIMAL NUMBER SYSTEMS?
 
The main reason why we use hexadecimal numbers is because it is much easier to express binary number representations in hex than it is in any other base number system. Computers do not actually work in hex (don’t laugh, beginning students do ask that question). Let’s look at an example, using a byte. Bytes are typically 8 bits, and can store the values 0 – 255 (0000 0000 – 1111 1111 in binary). For people, expressing numbers in binary is not convenient. I am not going to turn around to my co-worker and tell him that my phone number is 101 101 101 001 010 001 010 for obvious reasons. Imagine having to try and work with that on a daily basis. So a more convenient expression is needed for the humans.
 
Since a byte is 8 bits, it makes sense to divide that up into two groups, the top 4 bits and the low 4 bits. Since 4 bits gives you the possible range from 0 – 15, a base 16 system is easier to work with, especially if you are only familiar with alphanumeric characters. It’s easier to express a binary value to another person as “A” then it is to express it as “1010”. This way I can simply use 2 hex values to represent a byte and have it work cleanly. This way even if my math is poor, I only need to memorize the multiplication tables up to 15. So if I have a hex value of “CE”, I can easily determine that (12 * 161) + (14*160) = 206 in decimal, and can easily write it out in binary as 1100 1110. Trying to convert from binary would require me to know what each place holder represents, and add all the values together (128 + 64 + 8 + 4 + 2 = 206). It’s much easier to work with binary through hex than any other base system.

CONVERSION TECHNIQUES:

HEXADECIMAL TO BINARY AND BINARY TO HEXADECIMAL NUMBER SYSTEM:

Let’s assume we have a binary number of: 01010111
 
Hexadecimal =??
84218421
01010111
0 x 81 x 40 x 21 x 10 x 81 x 41 x 21 x 1
04010421
0 + 4 + 0 + 1  = 5    0 + 4 + 2 + 1 = 7  
5    7  

Hence the hexadecimal equivalent is 57

From Denary to Hexadecimal:
117 (in denary) is 7 lots of 16 (112) plus an extra 5. Fitting this in the columns gives
256161
075

Notice that 7 in binary is 0111 and that 5 is 0101, put them together and we get 01110101 which is the binary value of 117 again. So binary and hexadecimal are all related in some way.

FROM HEXADECIMAL TO BINARY AND DENARY:

Hexadecimal number BD stands for 11 lots of 16 and 13 units

= 176 + 13

= 189 (in denary)

Note: B = 11, which in binary = 1011

D = 13, which in binary = 1101

Put them together to get 10111101 = the binary value of 189.

USE OF HEXADECIMAL NUMBER IN COMPUTER REGISTERS AND MAIN MEMORY:

Computers are comprised of chips, registers, transistors, resistors, processors, traces, and all kinds of things. To get the binary bits from one place to the next, software programmers convert binary to hex and move hex values around. In reality, the computer is still shoving 1's and 0's along the traces to the chips.

There are two important aspects to the beauty of using Hexadecimal with computers: First, it can represent 16-bit words in only four Hex digits, or 8-bit bytes in just two; thus, by using a numeration with more symbols, it is both easier to work with (saving paper and screen space) and makes it possible to understand some of the vast streams of data inside a computer merely by looking at the Hex output. This is why programs such as DEBUG, use only Hexadecimal to display the actual Binary bytes of a Memory Dump rather than a huge number of ones and zeros!

The second aspect is closely related: Whenever it is necessary to convert the Hex representation back into the actual Binary bits, the process is simple enough to be done in your own mind. For example, FAD7 hex is 1111 1010 1101 0111 (F=1111, A=1010, D=1101, 7=0111) in Binary. The reason one might wish to do this is in order to work with "logical" (AND, OR or XOR) or "bit-oriented" instructions (Bit tests, etc.) which may make it easier (at times) for a programmer to comprehend.

For example, if you wanted to logically AND the hex number FAD7 with D37E, you might have a difficult time without first changing these numbers into Binary. If you jot them out in Binary on scratch paper, the task will be much easier:

FAD7 hex1111101011010111
D37E hex1101001101111110
ANDing gives1101001001010110
Answer in hexD256

USES OF HEXADECIMAL IN COMPUTING:

HTML COLORS:

Along with the advances in Microcomputers, "the Internet" has experienced many changes as well. A code still used by "Web browsers" today had been invented to transfer information from servers to terminals in a way that made the Internet a much more effective tool for research. That code is called "Hyper-Text Markup Language" (or HTML) and it soon included a method which could theoretically reproduce background and text with a total of 16,777,216 different colors!

The hardware available today has already advanced way beyond that limit. The main reason was a push to display pictures "in living color;" now a common reality. And one of the first things a new computer user should always do is make sure their display can be set to what's called "24-bit" or "True Color" (for those 16-million plus possible colors). As a matter of fact, almost every video card today has the capacity to reproduce what's called "32-bit" color. But all those extra bits are not used for increasing the number of colors! Why? Well, since the human eye is only capable of distinguishing something like 7 million or so different colors that would be a real waste of technology! But you'll have to look for another page about video cards if you want to know more; our task here is to simply explain the use of color with HTML code.

Hexadecimal color values are supported in all major browsers. A hexadecimal color is specified with: #RRGGBB, where the RR (red), GG (green) and BB (blue) hexadecimal integers specify the components of the color. All values must be between 00 and FF.

For example, the #0000FF value is rendered as blue, because the blue component is set to its highest value (FF) and the others are set to the lowest value (00).Computers are comprised of chips, registers, transistors, resistors, processors, traces, and all kinds of things. To get the binary bits from one place to the next, software programmers convert binary to hex and move hex values around. In reality, the computer is still shoving 1's and 0's along the traces to the chips.

ASSEMBLY LANGUAGE:

In 8 bit PC register, the largest number is 1111 1111 which has 8 bits. At the same time the 2 digit hexadecimal number for 1111 1111 is ‘FF’.

Do you see how skillfully it is used? Don’t forget that computers process 8-digit binary numbers. For the convenient use of programmer in Assembly language, it is easy to manipulate hexadecimal numbers rather than binary numbers.

In Assembly Language, you would move a HEX value into a register like so:

Mov AX,03

The command is MOV or move. The item to move is the value of 3. Where? Into the AX register.

MAC ADDRESS:
A typical MAC address looks something like this: af-14-b3-c2-14-45

You may be wondering why we've got letters and numbers in this address. MAC addresses are expressed in hexadecimal, which gives us the ability to express more values with the same number of bits.

Theoretically, every single NIC in the world should have a totally unique MAC address, and the only way to do this is to express MAC addresses in hexadecimal.

 GCSE \ IGCSE O Level Computer Science 0478 P1 Hexadecimal 

GCSE \ IGCSE O Level Computer Science 0478 P1 Hexadecimal

Post a Comment

Previous Post Next Post