binara_tal_2011_D3

Download Report

Transcript binara_tal_2011_D3

Styrteknik: Binära tal, talsystem och koder
Digitala kursmoment
D1 Boolesk algebra
D2 Grundläggande logiska funktioner
D3 Binära tal, talsystem och koder
D3:1
Styrteknik :Binära tal, talsystem och koder
Inga kommentarer……
D3:2
Styrteknik :Binära tal, talsystem och koder
Decimaltal:
34310 = 3*102 + 4*101 + 3 *100
Basen 10, siffrorna 0,1,2,3,4,5,6,7,8,9
Binärtal:
1011012 =1*25+0*24+1*23+1*22+0*21+1*20
Basen 2, siffrorna 0,1
(1011012 =1*32+0*16+1*8+1*4+0*2+1*1 = 4510
D3:3
Styrteknik :Binära tal, talsystem och koder
D3:4
Omvandlingar Decimaltal=>Binärtal:
23210
128
64
32
16
8
4
2
1
1
1
1
0
1
0
0
0
=
232-128=104
104-64= 40
40 = 32 + 8
23210
=
23210 = 111010002
Styrteknik :Binära tal, talsystem och koder
Omvandlingar Binärtal => Decimaltal:
111111112 = 128+64+32+16+8+4+2+1 = 25510
För positiva heltal gäller:
8 bitar => Största heltal 28 – 1 = 256 - 1 = 255
16 bitar => Största heltal 216 -1 = 65 535
32 bitar => Största heltal 232-1 = 4 294 967 295
D3:5
Styrteknik :Binära tal, talsystem och koder
D3:6
Heltal på tvåkomplementform
011 = +3
010 = +2
001 = +1
000 = +0
111 = -1
110 = -2
101 = -3
100 = -4
Styrteknik :Binära tal, talsystem och koder
För heltal på tvåkomplementform gäller:
8 bitar => 01111111 = +127
00000000 = 0
11111111 = -1
10000000 = -128
Talområde +127 till -128
Talområde för:
16 bitar => +32 767 till -32 268
32 bitar => +2 147 483 647 till -2 147 483 648
D3:7
Styrteknik :Binära tal, talsystem och koder
D3:8
Hexadecimala tal:
Basen 16, Siffrorna 0..9, A,B,C,D,E,F
Ex: 3AF16
= 3*162 + 10*161 +15*160 =
= 3*256+16*10+15*1 = 94310
Omvandling hexadecimalt-binärt, varje siffra skrivs med 4 bitar:
Ex: 3AF = 0011 1010 1111 = 1110101111
1010111110 = 0010 1011 1110 = 2BE
Styrteknik :Binära tal, talsystem och koder
Hexadecimal tabell:
0
1
2
3
4
5
6
7
0000
0001
0010
0011
0100
0101
0110
0111
8
9
(10) A
(11) B
(12) C
(13) D
(14) E
(15) F
1000
1001
1010
1011
1100
1101
1110
1111
D3:9
Styrteknik :Binära tal, talsystem och koder
BCD-kod Binary Coded Decimal:
Varje decimal siffra kodas med 4 bitar.
Ex 93710 = 1001 0011 0111 (BCD)
Koden har vikterna 8421
ASCII-kod (American Standard Code for
Information Interchange):
Ex: 7 bitars ASCII:
A = X100 0001 = 41
C = X100 0011 = 43
X biten kan användas som kontrollbit
Ex: Jämn paritet A = 0100 0001
C = 1100 0011
Även 8-bitars ASCII-kod är vanlig
D3:10
Styrteknik :Binära tal, talsystem och koder
D3:11
Gray-kod
0
1
2
3
4
5
6
7
000
001
011
010
110
111
101
100
Används för olika typer av läges- eller
vinkelgivare. Koden ändras bara i en bit
mellan två närliggande värden.
Styrteknik :Binära tal, talsystem och koder
D3:12
We can then manipulate the inputs or outputs using Boolean operations. Boolean
algebra has been discussed before for variables with single values, but it is the same for
multiple bits. Common operations that use multiple bits in numbers are shown in Figure
13.8. These operations compare only one bit at a time in the number, except the shift
instructions that move all the bits one place left or right.
Bitvis AND, OR, …..
Styrteknik :Binära tal, talsystem och koder
D3:13
Binary numbers come in three basic forms - a bit, a byte and a word. A bit is a single
binary digit, a byte is eight binary digits, and a word is 16 digits. Words and bytes are
shown in Figure 13.5. Notice that on both numbers the least significant digit is on the right
hand side of the numbers. And, in the word there are two bytes, and the right hand one is
the least significant byte.
Styrteknik :Binära tal, talsystem och koder
Olika binära talsystem
OBS För signed finns de två värden för 0:
0000 0000 = 0 (positiv nolla?)
1000 0000 = 0 (negativ nolla?)
D3:14
Styrteknik :Binära tal, talsystem och koder
Addition av tal på 2-komplementform.
8-bitars tal
Talområde: +127 till -128
Resultat utanför talområdet
ska ge overflow (OF, O).
D3:15
Styrteknik :Binära tal, talsystem och koder
D3:16
Paritet
Errors often occur when data is transmitted or stored. This is very important when
transmitting data in noisy factories, over phone lines, etc. Parity bits can be added to data
as a simple check of transmitted data for errors. If the data contains error it can be
retransmitted,or ignored.
Parity bits are normally suitable for single bytes, but are
not reliable for data with a number of bits.
Styrteknik :Binära tal, talsystem och koder
Checksummor
Checksums are very common in data transmission, but these are also hidden from
the average user. If you plan to transmit data to or from a PLC you will need to
considerparity and checksum values to verify the data. Small errors in data can have
major consequencesin received data.
Consider an oven temperature transmitted as a binary integer (1023d = 0000 0100
0000 0000b). If a single bit were to be changed, and was not detected
the temperature might become (0000 0110 0000 0000b = 1535d) This small change
woulddramatically change the process.
D3:17
Styrteknik :Binära tal, talsystem och koder
D3:18
Styrteknik :Binära tal, talsystem och koder
5. Convert the BCD number below to a decimal number,
0110 0010 0111 1001
6. Convert the following binary number to a BCD number,
0100 1011
7. Convert the following binary number to a Hexadecimal value,
0100 1011
8. Convert the following binary number to a octal,
0100 1011
9. Convert the decimal value below to a binary byte, and then
determine the odd parity bit,
97
10. Convert the following from binary to decimal, hexadecimal, BCD
and octal.
a) 101101
b) 11011011
c) 10000000001
d) 0010110110101
D3:19
Styrteknik :Binära tal, talsystem och koder
11. Convert the following from decimal to binary, hexadecimal, BCD and octal.
a) 1
b) 17
c) 20456
d) -10
12. Convert the following from hexadecimal to binary, decimal, BCD and octal.
a) 1
b) 17
c) ABC
d) –A
13. Convert the following from BCD to binary, decimal, hexadecimal and octal.
a) 1001
b) 1001 0011
c) 0011 0110 0001 d) 0000 0101 0111 0100
D3:20