The text of a manual · part 52 of 55
Hand-Held Terminal (Catalog Number 1747-PT1) User Manual: B - Number Systems, Hex Mask
Pages 449 to 454 of 486, from Hand-Held Terminal (Catalog Number 1747-PT1) User Manual
The original document is the PDF (1.5 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Allen-Bradley 1747-PT1
Page 449
Appendix
B
Number Systems, Hex Mask This appendix: • describes the different number systems you need to understand for use of the HHT with SLC 500 family controllers • covers binary, Binary Coded Decimal (BCD), and hexadecimal. • explains the use of a Hex mask used to filter data in certain programming instructions
Binary Numbers
The processor memory stores 16-bit binary numbers. As indicated in the figure below, each position in the number has a decimal value, beginning at the right with 20 and ending at the left with 215. Each position can be 0 or 1 in the processor memory. A 0 indicates a value of 0 at that position; a 1 indicates the decimal value of the position. The equivalent decimal value of the binary number is the sum of the position values.
Positive Decimal Values The far left position is always 0 for positive values. As indicated in the figure below, this limits the maximum positive decimal value to 32767. All positions are 1 except the far left position. 1x214 = 16384 16384 1x213 = 8192 8192 1x212 = 4096 4096 1x211 = 2048 2048 1x210 = 1024 1024 1x29 = 512 512 1x28 = 256 256 1x27 = 128 128 1x26 = 64 64 1x25 = 32 32 1x24 = 16 16 1x23 = 8 8 1x22 = 4 4 1x21 = 2 2 1x20 = 1 + 1 32767 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0x215 = 0
This position is always zero for positive numbers.
The binary number may also be converted to decimal as follows: 16 bit pattern = 01111111111111112 = 214 + 213 + 212 + 211 + 210 + 29 + 28 + 27 + 26 + 25 + 24 + 23 + 22 + 21 + 20 = 16384 + 8192 + 4096 + 2048 + 1024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 0 = 32767 B–1
Page 450
Appendix B Number Systems, Hex Mask
Other examples: 16 bit pattern = 0000 1001 0000 11102 = 211 + 28 + 23 + 22 + 21 = 2048 + 256 + 8 + 4 + 2 = 2318 16 bit pattern = 0010 0011 0010 10002 = 213 + 29 + 28 + 25 + 23 = 8192 + 512 + 256 + 32 + 8 = 9000
Negative Decimal Values The 2s complement notation is used. The far left position is always 1 for negative values. The equivalent decimal value of the binary number is obtained by subtracting the value of the far left position, 32768, from the sum of the values of the other positions. In the figure below all positions are 1, and the value is 32767 – 32768 = –1. 1x214 = 16384 16384 1x213 = 8192 8192 1x212 = 4096 4096 1x211 = 2048 2048 1x210 = 1024 1024 1x29 = 512 512 1x28 = 256 256 1x27 = 128 128 1x26 = 64 64 1x25 = 32 32 1x24 = 16 16 1x23 = 8 8 1x22 = 4 4 1x21 = 2 2 1x20 = 1 + 1 32767 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1x215 = 32768
This position is always 1 for negative numbers.
The negative binary number may be converted to decimal as follows: 16 bit pattern = 11111111111111112 = ( 214 + 213 + 212 + 211 + 210 + 29 + 28 + 27 + 26 + 25 + 24 + 23 + 22 + 21 + 20) – 215 = ( 16384 + 8192 + 4096 + 2048 + 1024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 0 ) – 32768 = 32767 – 32768 = –1
B–2
Page 451
Appendix B Number Systems, Hex Mask
Another example: 16–bit pattern = 1111 1000 0010 00112 = ( 214 + 213 + 212 + 211 + 25 = ( 16384 + 8192 + 4096 + 2048 + 32 = 30755 = –2013
+ 21 + 2
+ 20 ) – 215 + 1 ) – 32768 – 32768
An easier way to calculate a negative value is to locate the last “1” in the string of 1s beginning at the left, then subtract its value from the total value of positions to the right of that position.
For example: 16–bit pattern = 1111 1111 0001 10102 = ( 24 + 2 3 + 2 1 ) – 2 8 = ( 16 + 8 + 2 ) – 256 = –230
BCD Numbers
Binary Coded Decimal numbers use a 4–bit binary code to represent decimal values ranging from 0 to 9 as shown below: BCD Value 0 1 2 3 4 5 6 7 8 9
Binary Value 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
Thumbwheels and LED displays are two types of I/O devices that use BCD numbers. The position values of BCD numbers are powers of 2, as in binary, beginning with 20 at the right: 23
22
21
20
8
4
2
1
Position Decimal Value
B–3
Page 452
Appendix B Number Systems, Hex Mask
Example: BCD bit pattern 01112, for one digit, has a decimal equivalent value of 7: 0x23 = 0 1x22 = 4 1x21 = 2 1x20 = 1
+
0 4 2 1 7
0 1 1 1
To form multiple digit numbers, BCD uses a 16–bit pattern similar to binary. This allows up to 4 digits, using the above 4–bit binary code. BCD numbers have a range of 0 to 32,767 in the SLC 500 family processors. The following figure shows the BCD representation for the decimal number 9862:
Hexadecimal Numbers
Thousands
Hundreds
Tens
Ones
1 0 0 1
1 0 0 0
0 1 1 0
0 0 1 0
Binary Pattern
8 4 2 1
8 4 2 1
8 4 2 1
8 4 2 1
Position Values
9
8
6
2
Decimal value
Hexadecimal numbers use single characters 0 to 9 and A to F, to represent decimal values ranging from 0 to 15: HEX Decimal
0 1 2 3 4 5 6 7 8 9 A
B
C
D
E
F
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
The position values of hexadecimal numbers are powers of 16, beginning with 160 at the right: 163 162 161 160
Example: Hexadecimal number 218A has a decimal equivalent value of 8586: 2x163 = 8192 1x162 = 256 8x161 = 128 10x160 = 10 2 1 8 A
B–4
8192 256 128 10 8586
Page 453
Appendix B Number Systems, Hex Mask
Hexadecimal and binary numbers have the following equivalence: Hexadecimal
Binary
2 1 8 A
= 8586
0 0 1 0
0 0 0 1
1 0 0 0
1 0 1 0
8192 1x213
256 1x28
128 1x27
10 1x23+1x21
= 8586
Example: Decimal number –8586 in equivalent binary and hexadecimal forms: Binary
1 1 0 1
1 1 1 0
Hexadecimal
0 1 1 1
D E 7 6
0 1 1 0
= –8586
= 56950 (negative number, –8586)
Hex number DE76 = 13x163+14x162+7x161+6x160 = 56950. This is a negative number because it exceeds the maximum positive value of 32767. To calculate its value, subtract 164 (the next higher power of 16) from 56950: 56950 – 65536 = –8586.
Hex Mask
This is a 4-character code, entered as a parameter in SQO, SQC, and other instructions to exclude selected bits of a word from being operated on by the instruction. The hex values are used in their binary equivalent form, as indicated in the figure below. The figure also shows an example of a hex code and the corresponding mask word. Hex Value 0 1 2 3 4 5 6 7 8 9 A B C D E F
Binary Value 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Hex Code 0 0 F F
0 0 0 0
0 0 0 0
1 1 1 1
1 1 1 1
Mask Word
B–5
Page 454
Appendix B Number Systems, Hex Mask
Bits of the mask word that are set (1) pass data from a source to a destination. Reset bits (0) do not. In the example below, data in bits 0–7 of the source word is passed to the destination word. Data in bits 8–15 of the source word is not passed to the destination word. Destination bits 8–15 are not affected (they are left in their last state).
B–6
Source Word
1 1 1 0
1 0 0 1
1 1 0 0
1 0 1 0
Mask Word
0 0 0 0
0 0 0 0
1 1 1 1
1 1 1 1
Destination Word (all bits 0 initially)
0 0 0 0
0 0 0 0
1 1 0 0
1 0 1 0