Binary nombers and numbering systems, Slides von Elektrotechnik

Unvollständige Textvorschau

Nur auf Docsity: Lade Binary nombers and numbering systems und mehr Slides als PDF für Elektrotechnik herunter!

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik

Computing 1

International Bachelor Mechatronics (IMC)

Norbert Strobel

Room: Institut für Medizintechnik (IMeS), 1.1.59.

Telefon: 09721/ 940-

Email: [email protected]

Calculating using binary Numbers

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik

Computing Labs

Date Change for Group 3

  • Group 3: Thu: 8:15 - 9:45 Uhr - Start:17.10.2019 , Room 1.1.
  • Group 4: Thu: 8:15 - 9:45 Uhr - Start:17.10.2019, Room 1.1.

Due to a misunderstanding last week, both groups will start this Thursday, i.e.,

on 17.10.2019, with a joint session. Starting next week, we will return to the

original plan. That is, Group 3 on 24.10., Group 4 on 31.10., etc.

  • Labs will be held by Florian Spieß

Person and Room Change for Group 5 and Group 6

  • Group 5: Thu: 16:00 - 17:30 Uhr - Start: 10.10.2019, Room 1.1.
  • Group 6: Thu: 16:00 - 17:30 Uhr - Start:17.10.2019, Room 1.1.
  • Labs will be held by Dominik Mainusch

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik

1. Recap Numeral Systems and Codes

Representing an N-digit Number

Base of the numeral system:

Digit: 𝑎𝑎 (^) 𝑖𝑖 ∈ 0,1, … , 𝐵𝐵 − 1

Number: (𝑎𝑎 (^) 𝑁𝑁−1 𝑎𝑎𝑁𝑁−2 … 𝑎𝑎 0 )𝐵𝐵

Value: 𝑎𝑎 𝑁𝑁−1 𝐵𝐵𝑁𝑁−1^ + 𝑎𝑎 𝑁𝑁−2 𝐵𝐵𝑁𝑁−2^ + ⋯ +𝑎𝑎 0 𝐵𝐵 0 = ∑𝑖𝑖=

𝐵𝐵

Hochschule für angewandte Wissenschaften Würzburg-Schweinfurt - Fak. Elektrotechnik

Informatik 1

Dual (B=2)

Oktal (B=8)

Dezimal (B=10)

Hexadezimal (B=16)

0000 0 0 0

0001 1 1 1

0010 2 2 2

0011 3 3 3

0100 4 4 4

0101 5 5 5

0110 6 6 6

0111 7 7 7

1000 10 8 8

1001 11 9 9

1010 12 10 A

1011 13 11 B

1100 14 12 C

1101 15 13 D

1110 16 14 E

1111 17 15 F

−

=

1

0

N

i

i

Z ai B

1. Recap Numeral

Systems and Codes

Representation of an N-digit

Number

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik

1. Recap Numeral Systems and Codes

Series of Bits and Data Ranges for positive integer Numbers

  • 1 Bit: 0,1 (2 Numbers)
  • 2 Bit: 0 to 3 (4 Numbers)
  • 3 Bit: 0 to 7 (8 Numbers)
  • 4 Bit: 0 to 15 (16 Numbers)
  • 8 Bit: 0 to 255 (256 Numbers)
  • 16 Bit: 0 to 65535 (65536 Numbers)
  • 32 Bit: 0 to 4.294.967.295 (4.294.967.296 Numbers)
  • N Bit: 0 to 2N^ -1 (2N^ Numbers)

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik

1. Recap Numeral Systems and Codes

Conversion between Binary, Octal, and Decimal Numeral System

(Quelle: Herold et al., Pearson)

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik

Computer calculations are based on binary numbers.

The four basic calculations are:

1. Addition

2. Subtraction

3. Multiplication

4. Division

2. Calculating using binary Numbers

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik

Addition using binary numbers is similar to decimal addition except that

you have only two digits (0 and 1).

The following rules apply:

1 + 1 = 0, Carry = 1

The carry bit transports a 2 from right to left.

Example: (1010) 2 + (1001) 2 = (10011) 2

Addition

2. Calculating using binary Numbers

Carry

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik

Addition

Third Example

(0101 0110) 2 + (0110 0111)^2 = (1011 1101)^2

Carry

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik Addition

Problems

1. Add the following 8-Bit numbers: (0101 1011) 2 + (0010 0101) 2

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik

Carry Problem when adding unsigned Numbers

  • Carry problem can happen due to a fixed word length of a non-negative data

type in C++ such as unsigned char, unsigned short, unsigned

int, unsigned long, etc.

  • The fixed-length sum of two non-negative fixed-length numbers is wrong if the

addition causes a carry out of the most significant (leftmost) bits added.

4-Bit Example

1111 + 0001 = 0000 (wrong result)

  • In such a case, the CPU's carry flag is turned on.

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik

2. Calculating using binary Numbers

Addition using binary numbers is similar to decimal addition.

Also similar to decimal subtraction is the concept of "borrowing.“

The following rules apply:

0 - 1 = 1, Carry = 1 („borrowing“)

Note

In many practical cases, subtraction is carried out based on addition using

two‘s complement.

Subtraction

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik

Subtraction

2. Example

Carry

Hochschule für angewandte Wissenschaften Würzbug-Schweinfurt - Fakultät Elektrotechnik Subtraction

Problems

1. Subtract the following binary numbers: (0101 1011) 2 - (0010 0101) 2