When binary numbers are stored in a word (see above) the value of each digit (position) in the
word is one power of 2 higher than that of the digit to its right. The principle is exactly the same
as in decimal representation, but with increments of 2 instead of 10 (see graphic):
*
In binary values bit 15 is used to represent the sign (bit 15=0: positive value, bit 15=1: negative value)
To convert a binary value to a decimal value you just have to multiply each digit with a value of 1
by its corresponding power of 2 and calculate the sum of the results.
Example 00000010 00011001 (binary)
00000010 00011001 (binary) = 1 x 2
9
+1x2
4
+1x2
3
+1x2
0
00000010 00011001 (binary) = 512 + 16 + 8 + 1
00000010 00011001 (binary) = 537 (decimal)
Hexadecimal numbers
Hexadecimal numbers are easier to handle than binary and it is very easy to convert binary
numbers to hexadecimal. This is why hexadecimal numbers are used so often in digital tech
-
nology and programmable logic controllers. In the PLCs of the MELSEC System Q hexadeci
-
mal numbers are used for the numbering of inputs and outputs and the representation of con
-
stants. In the programming manual and other manuals hexadecimal numbers are always
identified with an H after the number to avoid confusion with decimal numbers (e.g.12345
H).
–
Base: 16
–
Digits:0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
(the letters A, B, C, D, E and F represent the decimal values 10, 11, 12, 13, 14 and 15)
The hexadecimal system works in the same way as the decimal system – you just count to F
H
(15) instead of to 9 before resetting to 0 and incrementing the next digit (FH à 10H,1FH à 20H,
2F
H à 30H,FFH à 100H etc). The value of digit is a power of 16, rather than a power of 10:
MELSEC System Q Beginners Manual 4 – 3
An Introduction to Programming Number Systems
0000000000 000
0
00
2
2
2
2
2
2
5
2
2
7
2
2
2
2
2
2
2
2
5
Base 2 Notation Decimal Value Base 2 Notation Decimal Value
2
0
12
8
256
2
1
22
9
512
2
2
42
10
1024
2
3
82
11
2048
2
4
16 2
12
4096
2
5
32 2
13
8192
2
6
64 2
14
16384
2
7
128 2
15
32768*
1A7FH
16
0
= 1 (in this example: 15 x 1 = 15)
16
1
= 16 (in this example: 7 x 16 = 112)
16
2
= 256 (in this example: 10 x 256 = 2560)
16
3
= 4096 (in this example: 1 x 4096 = 4096)
6783 (decimal)