Data Representation
Data Representation
Data Representation
Method 2:
The second method involves successive division by 2
until the value “0” is reached.
- Converting from Denary to Binary
- Converting from Denary to Binary
1.1.2 Binary, Denary, and Hexadecimal Systems
- The Hexadecimal Number System
What is the Hexadecimal Number System?
1) Binary to Hexadecimal
2) Hexadecimal to Binary
3) Hexadecimal to Denary
4) Denary to Hexadecimal
- Converting from Binary to Hexadecimal
Starting from the right and moving left, split the binary number
into groups of 4 bits.
If the last group has less than 4 bits, then simply fill in with 0s
from the left.
Remember that:
» Error codes
» MAC addresses
» IPv6 addresses
» HTML colour codes
1. Error Codes
• Error codes are often shown as hexadecimal values.
• These numbers refer to the memory location of the error and are usually
automatically generated by the computer.
• The programmer needs to know how to interpret the hexadecimal error codes.
a8fb:7a88:fff0:0fff:3d21:2085:66fb:f0fa
4. HyperText Mark-up Language Color Codes
• HTML is used when writing and developing web pages.
• HTML isn’t a programming language but is simply a mark-up language.
• A mark-up language is used in the processing, definition and presentation of text
(for example, specifying the colour of the text).
• HTML uses <tags> which are used to bracket a piece of text for example, <h1>
• and </h1> surround a top-level heading.
• Whatever is between the two tags has been defined as heading level 1. Here is a
short example of HTML code:
• HTML is often used to represent colors of text on the computer screen.
• All colours can be made up of different combinations of the three primary colours
• (red, green and blue).
• The different intensity of each colour (red, green and blue) is determined by its
hexadecimal value.
• This means different hexadecimal values represent different colours.
• There are a possible 256 values for red, 256 values for green and 256 values for
blue giving a total of 256 × 256 × 256 (i.e. 16 777 216) possible colours.
For example:
» # FF 00 00 represents primary colour red
» # 00 FF 00 represents primary colour green
» # 00 00 FF represents primary colour blue
» # FF 00 FF represents fuchsia
» # FF 80 00 represents orange
» # B1 89 04 represents a tan colour
1.1.4 Addition of Binary Numbers
The addition of two 8-bit positive binary numbers
Overflow
• This addition has generated a 9th bit. The 8 bits
of the answer are 0 1 0 0 1 1 0 0
• This gives the denary value (64 + 8 + 4) of 76
which is incorrect because the denary value of
the addition is 110 + 222 = 332.
• The maximum denary value of an 8-bit binary
number is 255 (which is 28 – 1).
• The generation of a 9th bit is a clear indication
that the sum has exceeded this value.
• Up until now, we have assumed all binary numbers are positive integers.
• To allow the possibility of representing negative integers we make use of
two’s complement.
• In this section we will again assume 8-bit registers are being used.
• Only one minor change to the binary headings needs to be introduced
here:
1.1.6 Two’s Complement (binary numbers)
• In two’s complement the left-most bit is changed to a negative value.
• For instance, for an 8-bit number, the value 128 is now changed to −128, but all
the other headings remain the same.
• This means the new range of possible numbers is:
−128 (10000000) to +127 (01111111).
• It is important to realize when applying two’s complement to a binary number
that the left-most bit always determines the sign (+ or -) of the binary.
• A 1-value in the left-most bit indicates a negative number (00110011 = 51)
• A 0-value in the left-most bit indicates a posi ve number (11001111 = −49)
Writing positive binary numbers in two’s complement format
Converting positive denary numbers to binary numbers in the
two’s complement format
Converting positive binary numbers in the two’s complement
format to positive denary numbers
Writing negative binary numbers in two’s complement format
and converting to denary
Converting negative denary numbers into binary numbers in
two’s complement format