chapter3
chapter3
Chapter 3
Number systems
Number systems
• Decimal system
This is based on the use of the 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. With a number represented by this system, the
digit position in the number indicates the weight attached to each digit.
Number systems
• The binary system
The binary system is based on just two digits: 0 and 1. These are termed binary digits or bits. When a number is
represented by this system, the digit position in the number indicates the weight attached to each digit,
The bit 0 is termed the least significant bit (LSB) and the highest bit the most significant bit (MSB). For
example, with the binary number 1010, the least significant bit is the bit at the right-hand end of the
number and so is 0. The most significant bit is the bit at the left-hand end of the number and so is 1
Number systems
The conversion of a decimal number to a binary number involves looking for the appropriate powers of 2. We can do this
by successive divisions by 2, noting the remainders at each division.
The binary number is 11111. The first division gives the least significant bit because we have just divided the 31 by 2
Number systems
• Octal and hexadecimal
Octal or hexadecimal numbers are sometimes used to make numbers easier to handle and act as a ‘half-way
house’ between denary numbers and the binary numbers which computers work with.
For example,
The denary number 9 which involves just a single digit requires four when written as the binary number 1001.
The denary number 181, involving three digits, in binary form is 10110101 and requires eight digits.
Number systems
• Octal system
The octal system is based on eight digits: 0, 1, 2, 3, 4, 5, 6, 7. When a number is represented by this system,
the digit position in the number indicates the weight attached to each digit
To convert denary numbers to octal we successively divide by 8 and note the remainders. Thus, the denary
number 15 divided by 8 gives 1 with remainder 7 and thus the denary number 15 is 17 in the octal system.
For example,
the octal number 365 is (3 % 82 )+( 6 % 81 )+ (5 % 80 )= 245.
Number systems
• Octal system
For example, the binary number 11010110 would be written as:
11 010 110
Each group is then replaced by the corresponding digit 0 to 7. The 110 binary number is 6, the 010 is 2 and the 11
is 3. Thus, the octal number is 326. As another example, the binary number 100111010 is:
100 111 010 (Binary)
472 (Octal)
Octal to binary conversion involves converting each octal digit into its 3-bit equivalent. Thus, for the octal number
21 we have 1 as 001 and 2 as 010:
2 1 Octal number
010 001 Binary number
and so the binary number is 010001.
Number systems
• Hexadecimal system
The hexadecimal system (hex) is based on 16 digits/symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. When a
number is represented by this system,
Thus, the decimal number 156 when divided by 16 gives 9 with remainder 12 and so in hex is 9C.
- To convert binary numbers into hexadecimal numbers, we group the binary numbers into fours starting from the least
significant number. Thus, for the binary number 1110100110 we have:
11 1010 0110 (Binary number)
3 A 6 (Hex number)
- For conversion from hex to binary, each hex number is converted to its 4-bit equivalent. Thus, for the hex number 1D
we have 0001 for the 1 and
1101 for the D:
1 D (Hex number)
0001 1101 (Binary number )
Number systems
• Binary coded decimal system (BCD).
An alternative method that is often used to link between the position of digits in a decimal number and the position
of digits in a binary number.
With this system, each denary digit is coded separately in binary. For example, the denary number 15 has
the 5 converted into the binary number 0101 and the 1 into 0001:
15 (Decimal number)
0001 0101 (Binary number)
to give in BCD the number 0001 0101
Number systems
Number systems
• Binary arithmetic
Addition of binary numbers uses the following Subtraction of binary numbers follows the following rules:
rules: 0−0=0
0+0=0 1−0=1
0+1=1+0=1 1−1=0
1 + 1 = 10 When evaluating 0 − 1, a 1 is borrowed from the next column
1 + 1 + 1 = 11 on the left
Consider the addition of the binary numbers 01110 containing a 1. The following example illustrates this with the
and 10011. subtraction
of 01110 from 11011:
Number systems
• Signed numbers
This can be done by adding a sign bit. When a number is said to be signed then the most significant bit is used
to indicate the sign of the number, a 0 being used if the number is positive and a 1 if it is negative.
XXXX XXXX
Sign bit
When we have a positive number then we write it in the normal way with a 0 preceding it. Thus, a positive binary
number of 10110 would be written as 010110. A negative number of 10110 would be written as 110110.
Number systems
• PLC data
- A 16-bit word, the term word being used for the group of bits constituting some information. This allows a
positive number in the range 0 to +65 535, i.e. 1111 1111 1111 1111, to be represented or a signed number in
the range –32 768 to +32 767 in two’s complement, the most significant bit then representing the sign.
- Such signed numbers are referred to as integers with the symbol INT being used with inputs and outputs in
programs of such 16-bit words. The term SINT is used for short integer numbers where only 8-bits are used,
such numbers giving the range –128 to +127. The term DINT is used for double integer numbers where 32
bits are used, such numbers giving the range –231 to +231 – 1. LINT is used for long integer numbers where 64
bits are used, such numbers giving the range –263 to +263 – 1.
Number systems
• PLC data
- Decimal fractions are referred to as real being represented by the symbol REAL for inputs and outputs in
programs. These consist of two 16-bit words.
- The term LREAL is used for long real numbers where 64 bits are used.
- The term BOOL is used for Boolean type data, such data being on/off values, i.e. 0 or 1, and thus represented
by single bits.
Time duration, e.g. for the duration of a process, is represented by the IEC (International Electrotechnical
Commission) standard using the symbols d for days, h for hours, m for minutes, s for seconds and ms for
milliseconds as, for example, T#12d2h5s3ms