number codes

23
Number Codes Digital Logic and Software Principles © University of Wales Newport 2009 This work is licensed under a Creative Commons Attribution 2.0 License .

Category:

Education


1 download

DESCRIPTION

The following presentation is a part of the level 4 module -- Digital Logic and Signal Principles. This resources is a part of the 2009/2010 Engineering (foundation degree, BEng and HN) courses from University of Wales Newport (course codes H101, H691, H620, HH37 and 001H). This resource is a part of the core modules for the full time 1st year undergraduate programme. The BEng & Foundation Degrees and HNC/D in Engineering are designed to meet the needs of employers by placing the emphasis on the theoretical, practical and vocational aspects of engineering within the workplace and beyond. Engineering is becoming more high profile, and therefore more in demand as a skill set, in today’s high-tech world. This course has been designed to provide you with knowledge, skills and practical experience encountered in everyday engineering environments.

TRANSCRIPT

Page 1: Number codes

Number Codes

Digital Logic and

Software Principles

© University of Wales Newport 2009 This work is licensed under a Creative Commons Attribution 2.0 License.

Page 2: Number codes

The following presentation is a part of the level 4 module -- Digital Logic and Signal Principles. This resources is a part of the 2009/2010 Engineering (foundation degree, BEng and HN) courses from University of Wales Newport (course codes H101, H691, H620, HH37 and 001H). This resource is a part of the core modules for the full time 1st year undergraduate programme.

The BEng & Foundation Degrees and HNC/D in Engineering are designed to meet the needs of employers by placing the emphasis on the theoretical, practical and vocational aspects of engineering within the workplace and beyond. Engineering is becoming more high profile, and therefore more in demand as a skill set, in today’s high-tech world. This course has been designed to provide you with knowledge, skills and practical experience encountered in everyday engineering environments.

Contents BCD Numbers Converting between Decimal and BCD From One-Byte BCD to Binary: BCD Addition BCD Subtraction Other Codes Gray Code Shaft Encoder Credits

In addition to the resource below, there are supporting documents which should be used in combination with this resource. Please see:

Holdsworth B, Digital Logic Design, Newnes 2002 Crisp J, Introduction to Digital Systems, Newnes 2001

Number Codes

Page 3: Number codes

Binary Coded Decimal BCD Numbers

Each decimal digit to be represented in BCD is converted into its 4 digit binary equivalent. The final number will consist of four times the number of original decimal digits.

As the decimal digits relating to 1010, 1011, 1100, 1101, 1110, 1111 do not exist these are invalid.

Decimal Binary BCD

0 0000 0000 0000 0000

1 0000 0001 0000 0001

2 0000 0010 0000 0010

3 0000 0011 0000 0011

4 0000 0100 0000 0100

5 0000 0101 0000 0101

6 0000 0110 0000 0110

7 0000 0111 0000 0111

8 0000 1000 0000 1000

9 0000 1001 0000 1001

10 0000 1010 0001 0000

11 0000 1011 0001 0001

12 0000 1100 0001 0010

13 0000 1101 0001 0011

14 0000 1110 0001 0100

15 0000 1111 0001 0101

16 0001 0000 0001 0110

17 0001 0001 0001 0111

18 0001 0010 0001 1000

19 0001 0011 0001 1001

20 0001 0100 0010 0000

Page 4: Number codes

Converting between Decimal and BCD

From Decimal to BCD:   To convert decimal to binary replace each decimal digit by its binary equivalent and then concatenate the result.

For example,

27690010 0111 0110 1001 = 0010011101101001

Number Codes

Page 5: Number codes

From BCD to Decimal:

Group the bits from the left into fours – if leading zeroes have been removed so that the total number of digits are a multiple of four.

Convert each group into its decimal equivalent.

Example

110101011010010001

0011 0101 0110 1001 0001 3 5 6 9 1

Page 6: Number codes

BCD AdditionBCD numbers can be added as long as certain rules are followed – these are.

if the addition produces a carry or if it creates an invalid BCD numberthen correct the digit by adding six where the error occurred.For example,24 + 13 = 37 15 + 9 = 24 19 + 28 = 47

Number Codes

0010 0100

0001 0011

0011 0111

0001 0101

0000 1001

0001 1110

0000 0110

0010 0100

0001 10010010 10000100 00010000 01100100 0111

Page 7: Number codes

BCD SubtractionBCD numbers can be subtracted as long as certain rules are followed – these are.

if the subtraction produces a borrow or if it creates an invalid BCD numberthen correct the digit by subtracting six where the error occurred.For example,

37 - 12 = 25 65 – 19 = 4641 – 18 = 23

Number Codes

0011 0111

0001 0010

0010 0101

0110 0101

0001 1001

0100 1100

0000 0110

0100 0110

0100 00010001 10000010 10010000 01100010 0011

Page 8: Number codes

Other Codes

ASCII Representation of Digits (American Standard Code for Information Interchange)

ASCII is a code that allows not only decimal digits to be represented in binary format but also other non numerical characters. In its simplest form it has seven binary digits allowing the identification of 128 different characters. For the representation of the numbers from 0 to 9 we simply convert each digit to four bit binary and then add 011 to the left hand side.

5 0101 0110101decimal binary ASCII

Number Codes

Page 9: Number codes

EBCDIC Representation of Digits (Extended Binary Coded Decimal Interchange Code)

This is an eight bit code which is used to represent decimal numbers. The decimal number is converted to its four bit binary equivalent and then four ones are added to the left.

5 0101 11110101decimal binary EBCDIC

Number Codes

Page 10: Number codes

Excess-3 (XS3)

Excess three is the same as BCD but before the conversion takes place three is added to the decimal number. This means the following combinations do not exist as valid XS3 numbers.

0000 0001 0010 1101 1110 and 1111

This representation simplifies the addition process.

Rule: if the addition stage generates a carry add 3, if it does not subtract 3

Number Codes

Page 11: Number codes

For example,

24 + 13 = 37 15 + 9 = 24 19 + 28 = 47

Subtraction

Rule: if the subtraction stage requires a borrow subtract 3, if it does not add 3

Number Codes

0101 0111

0100 0110

1001 1101

0011- 0011-0110 1010

0100 1000

0011 1100

1000 0100

0011- 0011+0101 0111

0100 11000101 10111010 01110011- 0011+0111 1010

Page 12: Number codes

For example,

37 - 12 = 25 65 – 19 = 46 41 – 18 = 23

Number Codes

0110 1010

0100 0101

0010 0101

0011+ 0011+0101 1000

1001 1000

0100 1100

0100 1100

0011+ 0011-0111 1001

0111 01000100 10110010 10010011+ 0011-0101 0110

Page 13: Number codes

4221

This coding technique is used to produce a balanced number of 0s and 1s in a random sequence of decimal conversions

Rather than the multipliers scaling by a factor of 2 as we move to the left, the multipliers are

4, 2, 2, 1 not 8, 4, 2, 1

This is sometimes written 4221 BCD.

Number Codes

Page 14: Number codes

Summary

Digit ASCII EBCDIC XS3 4221

0 0011 0000 1111 0000 0011 0000

1 0011 0001 1111 0001 0100 0001

2 0011 0010 1111 0010 0101 0010

3 0011 0011 1111 0011 0110 0011

4 0011 0100 1111 0100 0111 1000

5 0011 0101 1111 0101 1000 0111

6 0011 0110 1111 0110 1001 1100

7 0011 0111 1111 0111 1010 1101

8 0011 1000 1111 1000 1011 1110

9 0011 1001 1111 1001 1100 1111Number Codes

Page 15: Number codes

Gray CodeIf the decimal numbers to be encoded are increasing or decreasing linearly e.g. 3 – 4 – 5 – 6 – 7 or 23 – 22 – 21 – 20 – 19 etcthen it is possible for the conversion process to cause ambiguities as the digits change. This can be prevented if Gray Codes are employed.

Begin with all zeros and change the least significant bit. Change the next bit and reflect previous lower significant bits. Carry on with this process.

Number Codes

Page 16: Number codes

Shaft EncoderThis converts rotary movement into a digital number. It takes the following form:

Encoder Disk

Light Sources

Light Detectors

Rotating Shaft

Number Codes

Page 17: Number codes

The encoder disk has areas that are opaque and areas that are transparent. As the disk turns light is passed to the detectors or blocked. The disk has the following form: complete this for binary code

01

2

3

4

5

678

9

10

11

12

13

14

15 Binary

Disk

Page 18: Number codes

Number Codes

Page 19: Number codes

As the disk rotates anticlockwise we will reach a point where the output is 0 1 1 1 which is the output for position 7. Further rotation will move us to segment 8 where the output is 1 0 0 0. Note that each of the four bits change their state during this transition.Problems arise due to the fact that the light sources and detectors can never be “perfectly” aligned and therefore one of the bits will change before the others.

Bit 0 first we have a reading of 0 1 1 0 position 6Bit 1 first we have a reading of 0 1 0 1 position 5Bit 2 first we have a reading of 0 0 1 1 position 3Bit 3 first we have a reading of 1 1 1 1 position 15

Number Codes

Page 20: Number codes

We can see that with this code we can have erroneous outputs, which could be very serious.For this reason we use Grey Code

Generation of Gray is as follows:

0 0 0 0 00 0 0 1 10 0 1 1 30 0 1 0 20 1 1 0 60 1 1 1 70 1 0 1 50 1 0 0 41 1 0 0 121 1 0 1 131 1 1 1 151 1 1 0 141 0 1 0 101 0 1 1 111 0 0 1 91 0 0 0 8

NoteOnly one bit changes as we move from one segment to the next – hence no possible erroneous outputs.Complete the Gray disk on the next page.How can we convert from Gray to Binary? Number Codes

Page 21: Number codes

01

2

3

4

5

678

9

10

11

12

13

14

15

Gray

Disk

Number Codes

Page 22: Number codes

Number Codes

Page 23: Number codes

This resource was created by the University of Wales Newport and released as an open educational resource through the Open Engineering Resources project of the HE Academy Engineering Subject Centre. The Open Engineering Resources project was funded by HEFCE and part of the JISC/HE Academy UKOER programme.

© 2009 University of Wales Newport

This work is licensed under a Creative Commons Attribution 2.0 License. The JISC logo is licensed under the terms of the Creative Commons Attribution-Non-Commercial-No Derivative Works 2.0 UK: England & Wales Licence.  All reproductions must comply with the terms of that licence.

The HEA logo is owned by the Higher Education Academy Limited may be freely distributed and copied for educational purposes only, provided that appropriate acknowledgement is given to the Higher Education Academy as the copyright holder and original publisher.

The name and logo of University of Wales Newport is a trade mark and all rights in it are reserved. The name and logo should not be reproduced without the express authorisation of the University.

Number Codes