any form of data needs to be converted into a binary format so that it can be processed by the computer.
The basic building block in all computers is the binary number system. This system is chosen because it only consists of 1s and 0s. Since computers contain millions and millions of tiny ‘switches’, which must be in the ON or OFF position, they can be represented by the binary system.
Denary uses ten separate digits, 0-9, to represent all values.
Denary number system counts in multiples of 10. This gives us the well-known headings of units (计数单位), 10s, 100s, 1000s, and so on.
Denary is known as a base 10 number system.
The binary number system is a base 2 number system. It is based on the number 2. Thus, only the two ‘values’ 0 and 1 can be used in this system to represent all values. Using the same method as denary, this gives the headings 20,21,22,23, and so on.
denary
binary
example
5432
1011
value
5×1000+4×100+3×10+2×1
1×8+0×4+1×2+1×1
digits
0-9
0-1
type
base 10 number system
base 2 number system
headings of units
100,101,102,103, ...
20,21,22,23, ...
binary to denary
Take each of the digits and multiply it by the heading values. Add all the resultant totals together to give the denary number.
example:
Convert the binary number, 11101110, into a denary number.
Convert the binary number, 011110001011, into a denary number. 1931
denary to binary
Method 1
The denary number 142 is made up of 128 + 8 + 4 + 2:
142 – 128 = 14;
14 – 8 = 6;
6 – 4 = 2;
2 – 2 = 0;
in each stage, subtract the largest possible power of 2 and keep doing this until the value 0 is reached.
128 + 8 + 4 + 2
1 0 0 0 1 1 1 0
Method 2
successive division by 2
Start with the denary number, and divide it by 2.
Write the result of the division including the remainder (even if it is 0)
then divide the quotient again by 2 and keep dividing until the result is zero.
Finally write down all the remainders in reverse order
59 = 1 1 1 0 1 1
exercise:
Convert the following denary numbers into binary (using both methods):
67
127
189
33000
4095
62307
The hexadecimal system
Hexadecimal (sometimes referred to as simply ‘hex’) is a base 16 system and therefore needs to use 16 different ‘digits’ to represent each value. the letters A to F are used to represent each hexadecimal (hex) digit:
Binary value
Hexadecimal value
Denary value
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
A
10
1011
B
11
1100
C
12
1101
D
13
1110
E
14
1111
F
15
The hexadecimal number system is very closely related to the binary system.
Since 16=24 this means that FOUR binary digits are equivalent to each hexadecimal digit.
hexadecimal
example
21F3A
value
2×65536+1×4096+15×256+3×16
digits
0-F
type
base 16 number system
headings of units
160,161,162,163, ...
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.
Take each group of 4 bits and convert it into the equivalent hexadecimal digit
1 0 1 1 1 1 1 0 0 0 0 1
1 0 1 11 1 1 00 0 0 1
BE1
exercise:
1 0 0 0 0 1 1 1 1 1 1 1 0 12 1 F D
1 0 0 0 1 0 0 1 1 1 1 0
0 0 1 0 0 1 1 1 1 1 1 1 0
hexadecimal to binary
take each hexadecimal digit
write down the 4-bit code which corresponds to the digit.
45A
0 1 0 0 0 1 0 1 1 0 1 0
hexadecimal to denary
Take each of the hexadecimal digits and multiply it by the heading values. Add all the resultant totals together to give the denary number.
the hex digits A → F need to be first converted to the values 10 → 15 before
carrying out the multiplication.
exercise:
45A1114
C8F3215
denary to hexadecimal
Successive division by 16 until the value 0 is reached. Write the result of the division including the remainder (even if it is 0) The hexadecimal number is obtained from the remainders written in reverse order.
exercise:
20047D4
8463210F
1.1.3 Use of the hexadecimal system
a computer can only work with binary data.
hexadecimal to be more convenient to use. One hex digit represents four binary digits: A complex binary number, such as 1101001010101111 can be written in hex as D2AF. The hex number is far easier for humans to remember, copy and work with.
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.
MAC addresses
Media Access Control (MAC) address refers to a number which uniquely identifies a device on a network.
refers to the network interface card (NIC) which is part of the device.
rarely changed so that a particular device can always be identified no matter where it is.
usually made up of 48 bits which are shown as 6 groups of two hexadecimal digits (although 64-bit addresses also exist): NN – NN – NN – DD – DD – DD or NN:NN:NN:DD:DD:DD
Very often lowercase hexadecimal letters are used in the MAC address: 00-1c-b3-4f-25-fe.
first half (NN-NN-NN)
second half (DD-DD-DD)
value
Identity Number of the manufacturer
Serial Number of the device
example
00-1C-B3 (Apple Corporation )
4F-25-FE
IPv6 addresses
Each device connected to a network is given an address known as the Internet Protocol (IP) address. IPv4 has recently been improved upon by the adoption of IPv6. An IPv6 address is a 128-bit number broken down into 16-bit chunks, represented by a hexadecimal number. Note IPv6 uses a colon (:) rather than a decimal point (.) as used in IPv4.
Type
IPv4
IPv6
Description
32-bit number
128-bit number
Representation
Decimal or hexadecimal
Hexadecimal
Example
109.108.158.1 (or 77.76.9e.01 in hex)
a8fb:7a88:fff0:0fff:3d21:2085:66fb
HTML colour codes
HyperText Mark-up Language (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.
example of HTML code:
html
<h1style="color:#FF0000;">This is a red heading</h1>
<h2style="color:#00FF00;">This is a green heading</h2>
<h3style="color:#0000FF;">This is a blue heading</h3>
HTML is often used to represent colours 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. For example:
#FF8000 represents orange
The # symbol always precedes hexadecimal values in HTML code. The colour codes are always six hexadecimal digits representing the red, green and blue components. 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.
1.1.4 Addition of binary numbers
Carry whenever the sum is greater than 1.
overflow
in the addition of two 8-bit positive binary numbers, the maximum denary value of an 8-bit binary number is 255 (which is 28
– 1). The generation of a 9th bit indicates that the sum has exceeded this value. This is known as an overflow error and in this case is an indication that a number is too big to be stored in the computer using 8 bits.
The greater the number of bits which can be used to represent a number then the larger the number that can be stored:
register type
Maximum Denary Value
16-bit register
65 535 (216–1)
32-bit register
4 294 967 295 (232–1)
1.1.5 Logical binary shifts
Computers can carry out a logical shift on a sequence of binary numbers. It means moving the binary number to the left or to the right.
Shift Operation
Effect
Shift Left
multiplying the binary number by 2
Shift Right
dividing the binary number by 2
As bits are shifted, any empty positions are replaced with a zero.
There is clearly a limit to the number of shifts which can be carried out if the binary number is stored in an 8-bit register:
The denary number 21 is 00010101 in binary. If we put this into an 8-bit register we shift the original binary number 00010101 four places left: The left-most 1-bit has been lost. In our 8-bit register the result of is 80 which is incorrect. This error is because we have exceeded the maximum number of left shifts possible using this register.
Decimal Number
Binary Number
Denary Result
21
00010101
-
Shifted 1 left
00101010
84 (21× 2)
Shifted 2 left
01010100
84 (21× 22)
Shifted 3 left
10101000
168 (21× 23)
Shifted 4 left
01010000
80 (error)
1.1.6 Two’s complement (binary numbers)
To allow the possibility of representing negative integers we make use of two’s complement. 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
when applying two’s complement to a binary number the left-most bit always determines the sign of the binary number. A 1-value in the left-most bit indicates a negative number and a 0-value in the leftmost bit indicates a positive number
1.2 Text, sound and images
The ASCII code system (American Standard Code for Information Interchange)
Extended ASCII
Unicode
-
ASCII
Extended ASCII
Unicode
year of publish
1963 newer version in 1986.
-
1991
numbers of bit
7bit
8bit
16-bit or 32-bit
note
does not represent characters in non-Western languages, for example Chinese characters.
DOS and Windows use different characters for some ASCII codes.
can represent all languages of the world, thus supporting many operating systems, search engines and internet browsers used globally.
character set
● consists of 7-bit codes (0 to 127 in denary or 00 to 7F in hexadecimal) that represent the letters, numbers and characters found on a standard keyboard, together with 32 control codes (that use codes 0 to 31 (denary) or 00 to 19 (hexadecimal)). ● the sixth bit changes from 1 to 0 when comparing the lowercase and uppercase of a character. ● the character sets (e.g. a to z, 0 to 9, etc.) are grouped together in sequence, which speeds up usability.
● uses 8-bit codes (0 to 255 in denary or 0 to FF in hexadecimal). This gives another 128 codes to allow for characters in non-English alphabets and for some graphical characters to be included
● There is overlap with standard ASCII code, since the first 128 (English) characters are the same. ● ASCII uses one byte to represent a character, whereas Unicode will support up to four bytes per character.
The Unicode consortium was set up in 1991. Version 1.0 was published with five goals; these were to:
create a universal standard that covered all languages and all writing systems
produce a more efficient coding system than ASCII
adopt uniform encoding where each character is encoded as 16-bit or 32-bit code
create unambiguous encoding where each 16-bit and 32-bit value always represents the same character
reserve part of the code for private use to enable a user to assign codes for their own characters and symbols (useful for Chinese and Japanese character sets, for example).