Sei sulla pagina 1di 96

Information Systems Fundamentals II

IS 121: Information Systems Fundamentals II

Data representations and encryptions; Basic logic used in programming.

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Objectives

Understanding a computers basic data units such as binary numbers, bits, bytes, words, etc. and their conversions from and to octal, decimal, and hexadecimal digits Understanding basic concepts of computer internal data representation, focusing on numeric data, character codes etc Understanding proposition calculus and logical operations

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Some Terminology

Data representation unit and processing unit

1. Binary Digits (Bits)


Two levels of status in computers electronic circuits

Whether the electric current passes through it or not


Whether the voltage is high or low

1 digit of the binary system represented by 1 or 0 Smallest unit that represents data inside the computer 1 bit can represent 2 values of data, 0 or 1 2 bits can represent 4 different values 00, 01, 10, 11
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 4

(or Table)

(or Row)

(or Column)

Bit representation
Switches
Current Lights

Open (0) or closed (1)


Not flowing (0) or flowing (1) Off (0) or on (1)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Numeric Conversion
2. Bytes

A byte is a unit that represents with 8 bits 1 character or number, 1 byte = 8 bits E.g. 00000000, 00000010, etc. 1 bit can be represented in 2 ways, i.e. combination of 8 bit patterns into 1 byte enables the representation of 28 = 256 types of information Using a 1-byte word, 256 different characters can be represented sufficient for most Western character sets

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Numeric Conversion
2. Bytes

However, the number of kanji (Chinese characters) amounts to thousands of different characters, hence a 1-byte word system is insufficient Two bytes are connected to obtain 16 bits, 216 = 65,536 A 2-byte word

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Numeric Conversion
3. Word

The smallest unit that represents data inside a computer Increase operation speed

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Numeric Conversion
4. Number systems

Binary system is used to simplify the structure of electronic circuits that make up a computer Hexadecimal number is a numeric value represented by 16 numerals from 0 to 15 to ease the representation of binary numbers for humans computers are capable of only using binary numbers

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

10

Numeric Systems

Also known as Base Systems or Radix Systems Available digits:


Decimal system (base 10) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary system (base 2) 0, 1 Octal system (base 8) 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal (base 16) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F where A=10,B=11,C=12,D=13,E=14,F=15
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 11

Numeric Data Representation

The true value of numbers are the same The representation of numbers vary

Decimal Binary Octal Hexadecimal


IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Numeric data representation


DECIMAL number (Radix/Base = 10) Weight Value Final (true) value BINARY number (Radix/Base = 2) Weight

2 104 2*104

1 103 2*103

9 102 2*102

9 101 9*101

8 100 8*100

20000 + 1000 + 900 + 90 + 8 = 2199810 1 24 1 23 0 22 0 21 1 20

Value
Final (true) value

1*24

1*23

0*22

0*21

0*20

16 + 8 + 0 + 0 + 1 = 252
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 13

Numeric data representation


OCTAL number (Radix/Base = 8) Weight Value Final (true) value HEXA number (Radix/Base = 16) Weight Value Final (true) value
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 14

Binary Arithmetic

Addition and subtraction of binary numbers

Addition

0 + 0 = 0 (or 010) 0 + 1 = 1 (or 110) 1 + 0 = 1 (or 110) 1 + 1 = 10 (or 210) 00=0 0 1 = -1 10=1 11=0

Subtraction

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

15

Binary Addition

Result = 1001102

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

16

Binary Subtraction

Result = 10102

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

17

Hexadecimal arithmetic
4. Addition and subtraction of hexadecimal numbers

Addition

Performed starting at the lowest (first from the right) digit A carry to the upper digit is performed when the result is higher than 16 Performed starting at the lowest (first from the right) digit A borrow from the upper digit is performed when the result is negative

Subtraction

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

18

Hexadecimal Addition

First column from right


D + 7 = (In the decimal system: 13 + 7 = 20) = 16 (carried 1) + 4 The sum of the first column is 4 and 1 is carried to the second column.

Second column from right


1 + 8 + 1 = (In the decimal system: 10) = A Carried from the first column

Third column from right


A + B = (In the decimal system: 10 + 11 = 21) = 16 (carried 1) + 5 The sum of the third column is 5 and 1 is carried to the fourth column.

The result is (15A4)16.


IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 19

Hexadecimal Subtraction

First column from right


Since 3 4 = 1, a borrow is performed from D in the second digit (D becomes C). 16 (borrowed 1) + 3 4 = F (In the decimal system: 19 4 = 15)

Second column from right


C 7 = 5 (In the decimal system: 12 7 = 5)

Third column
61=5

The result is (55F)16.


IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 20

Exercises

Compute the following


a) b) c) d)

2710 + 1510 110112 + 11112 338 + 178 1B16 + F16

Compute the following


a) b) c) d)

5010 2210 1100102 - 101102 628 268 3216 - 1616

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

21

Numeric data representation


Radix/Base

300010 = 3 * 10

Exponent

Representation of numeric data


1. Radix and weight

Decimal numbers weight and its meaning


10 is called Radix upper right of 10 (in this example, 4) is called exponent

Binary digits weight and its meaning Used to represent big, small amounts, and exponent to which the radix is raised
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 22

2. Auxiliary units and power representation

Radix/Base Conversion

In order to process numeric values in a computer, decimal numbers are converted into binary or hexadecimal numbers However, since we ordinarily use decimal numbers, it would be difficult to understand the meaning of the result of a process if it were represented by binary or hexadecimal numbers. This operation is called radix conversion The following radix/base conversion techniques will be discussed:
1.

2.
3. 4. 5. 6.

Decimal to Binary Binary to Decimal Binary to Hexadecimal Hexadecimal to Binary Octal to Binary Binary to Octal
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 23

1. Decimal to Binary (Integer)


1. 2. 3.

4.

Decimal integer is divided into 2 The quotient and remainder are obtained The quotient is divided into 2 again until the quotient becomes 0 The binary value is obtained by placing the remainder(s) in reverse order

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

24

1. Decimal to Binary (Integer)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

25

1. Decimal to Binary (Fraction)

Decimal fraction is multiplied by 2


Resulting integer portion is extracted (always be 0 or 1) Resulting fraction portion is multiplied by 2 Operation is repeated until the fraction portion becomes 0

When decimal fractions are converted into binary fractions, most of the times, the conversion is not finished, since no matter how many times the fraction portion is multiplied by 2, it will not become 0. Most decimal fractions become infinite binary fractions.

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

26

1. Decimal to Binary (Fraction)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

27

2. Binary to Decimal (Integer)

Performed by adding up the weights of each of the digits of the binary bit string

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

28

2. Binary to Decimal (Fraction)

Same technique as for binary integers.

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

29

3. Binary to Hexadecimal

4-bit binary strings are equivalent to 1 hexadecimal digit The binary number is divided into groups of 4 digits starting from the decimal point In the event that there is a bit string with less than 4 digits, the necessary number of 0s is added and the string is considered as a 4-bit string

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

30

3. Binary to Hexadecimal (Integer)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

31

3. Binary to Hexadecimal (Fraction)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

32

4. Hexadecimal to Binary (Integer)

1 digit of the hexadecimal number is represented with a 4-digit binary number

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

33

4. Hexadecimal to Binary (Fraction)

Same technique as per integer

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

34

5. Octal to Binary

Convert 1038 to its binary form

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

35

6. Binary to Octal

Convert 10000112 to Octal

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

36

Exercises

Convert into binary, octal and hexa


a) b)

c)

2710 1510 50.2210 110112 338 1B.F16

Convert into decimal


a) b) c)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

37

Octal-Binary Conversions

Binary to/from Octal conversion


Conversion of binary to/from octal (whole numbers) Conversion of octal fractions

In decimal, 26.9210 = (2 * 101) + (6 * 100) + (9 * 10-1) + (2 * 10-2) 0.48 means 4 * 8-1 = (4/8) 10 = 10 = 0.510 0.2118 means (2 * 8-1) + (1 * 8-2) + (1 * 8-3)
Binary fractions can be converted in a similar manner to octal as that of octal fractions The number can then be converted to decimal by adding up the whole numbers and convert the fractions to decimals

Conversion of binary fractions


IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

38

Quiz

Try this
A.

What number does the next digit position represent in the hexadecimal system?

?
B.

256

16

C.

D.

Use the answer to evaluate the decimal equivalent of 2A9D16 What is the highest decimal number which may be represented by four hexadecimal digits? What is the highest decimal number which may be represented by four octal digits?
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 39

Numeric Presentation
Fixed Point (Integers) Numeric Data Data Character Data Decimal Numbers Unpacked Decimal
Represented using decimal arithmetic

Binary Numbers Floating Point (Real Numbers)

Packed Decimal

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

40

Decimal digit representation


Binary coded decimal Unpacked decimal format Packed decimal format

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

41

Decimal digit representation


o

Binary-coded decimal (BCD) code

Uses 4-bit binary digits (correspond to numbers 0 to 9 of decimal system)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

42

Decimal digit representation


BCD code Example:

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

43

Decimal digit representation

Unpacked decimal format


Uses 1 byte for each digit of decimal number Represents values from 0 to 9 in least significant 4 bits of 1 byte and in most significant 4 bits (zone bits) Half of a byte is used (excepting the least significant byte) where the least significant half-byte is used to store the sign

1100 = +ve 1101 = -ve

Waste of resources (eliminated by packed decimal format)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

44

Decimal digit representation

Unpacked decimal format

+78910 = F7F8C916

-78910 = F7F8D916
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 45

Decimal digit representation


o

Packed decimal format


1 byte represents a numeric value of 2 digits the least significant 4 bits represent the sign bit pattern for the sign is the same as per unpacked decimal format

+78910 = 789C16

-78910 = 789D16
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 46

Questions

A) Represent 7089310

in Unpacked Decimal Format in Packed Decimal Format


in Unpacked Decimal Format in Packed Decimal Format

B) Represent 789310

C) F3F9C116 is represented in standard Unpacked Decimal Format


What is its equivalent in decimal? Possible solution?

D) 3F9C16 is represented in standard Packed Decimal Format


What is its equivalent in decimal? Possible solution?


IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 47

Decimal digit representation


o

Packed decimal format versus Unpacked decimal format

A numeric value can be represented by fewer bytes The conversion into the binary system is easy

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

48

Binary Representation

Representation of negative integers


Absolute value representation

0 for positive, 1 for negative

Complement representation

Decimal complement 9s complement 10s complement Binary complement 1s complement 2s complement

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

49

Binary Representation

Absolute value representation

Examples

(00001100)2 = (+12)10 (10001100)2 = (-12)10 (00000000)2 = +0 (10000000)2 = -0

Issues

Range of values (assumption: 7-bit absolute value representation used)

-63 to +63 equivalent to (26-1) to +(26-1)


IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 50

Binary Representation

Complement representation of negative numbers


Decimal complement The subtraction of each of the digits of a numeric value from the complement

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

51

Binary Representation

Binary complement

1s complement of a given numeric value is the result of the subtraction of each of the digits of this numeric value from 1, as a result, all the 0 and 1 bits of the original bit string are switched.

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

52

Binary Representation

Binary complement

2s complement is 1s complement + 1

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

53

Binary Representation

1s complement and 2s complement representation of negative numbers

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

54

Binary Representation

Advantages of 2s complement

Less complicated (only one zero value) Range of values to be represented is wider Subtractions can be performed with addition circuits, simplifying hardware structure

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

55

Binary Representation

1s complement and 2s complement representation of negative integers

range of represented numeric values when n-bit binary number is represented by adopting the 1s complement method:

-(2n-1 1) to (2n-1 1)

range of represented numeric values when n-bit binary number is represented by adopting the 2s complement method:

-(2n-1) to (2n-1 1)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

56

Binary Representation

Addition circuits only

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

57

Binary Representation (Fixed Point)

Fixed point

Integer representation

Fixed point is a data representation format used mainly when integer type data is processed One word is represented in a fixed length (e.g. 16 bits and 32 bits) Overflow problem when attempt is made to represent a numeric value that exceeds the fixed length allocated
Decimal point is considered to be immediately preceded by the sign bit

Fraction representation

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

58

Binary Representation (Fixed Point)

Fixed point

Integer representation Range of values


-(2n-1) to (2n-1 1)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

59

Binary Presentation (Fixed Point)

Fixed point

Fraction representation

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

60

Binary Representation (Floating Point)

Floating point

Used to represent real number type data Used to represent extremely large or small size of data

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

61

Bit Shift Operations

Using bit shifts, the multiplication and division of numeric values can be easily performed

Shifting a binary digit 1 bit to the left, its value is doubled.


When a binary number is shifted n bits to the left, its former value is increased 2n times When a binary number is shifted n bits to the right, its former value decreases 2-n times (divided by 2n)
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 62

Arithmetic Shift

To calculate numeric values in the fixed point format using 2s complement representation Rules

Sign bit is not shifted Bit shifted out is lost Bit to be filled into the bit position is vacated as a result of the shift is

For left shifts, insert 0 For right shifts, insert the same bit as the sign bit

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

63

Logical Shift

To change the bit position Rules


Sign bit is also shifted (moved) Bit shifted out is lost Bit to be filled into the bit position vacated as a result of the shift is 0.

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

64

Bit Shifts

(-16)2 to be shifted 2 bits to the right Arithmetic Shift

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

65

Bit Shifts

Logical Shift

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

66

Operation and Precision

Precision of the numeric value presentation


o

o
o

The precision of a number is the range of its error High precision = small error Single precision

Range of numeric values presentable with 16 bits (in the case of an integer without a sign)
Minimum value = (0000 0000 0000 0000)2 = 0 Maximum value = (1111 1111 1111 1111)2 = 65,535 (values higher than 65,535 cannot be represented)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 67

Operation and Precision

Range of numeric values presentable with 16 bits (in the case of a fraction without a sign)
Minimum value = (0000 0000 0000 0001)2 = 2-16 = 0.0000152587890625000 Maximum value = (1111 1111 1111 1111)2 = 1 2 16 = 0.9999847412109370000 (values lower than 0.00001525878, and values higher than 0.99984741210937 cannot be represented)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

68

Operation and Precision


o

Double precision

Number of digits is increased to widen the range of represented numeric values Represent 1 numeric value with 2 words 1 numeric value presentable with 32 bits (in the case of an integer without a sign)
Minimum value = (0000 0000 0000 0000 0000 0000 0000 0000)2 = 0 Maximum value = (1111 1111 1111 1111 1111 1111 1111 1111)2 = 4,294,967,295 (values up to 4,294,967,295 can be represented)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 69

Operation and Precision

Range of numeric values presentable with 16 bits (in the case of a fraction without a sign)

Minimum value = (0000 0000 0000 0000 0000 0000 0000 0001)2 = 2-32 = 0.00000000023283064365387 Maximum value = (1111 1111 1111 1111 1111 1111 1111 1111)2 = 1 2 32 = 0.99999999976716900000000

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

70

Operation and Precision

Operation precision
o

Precision of fixed point representation


Range of presentable numeric values depends on the computer hardware (number of bits in one word) Range of represented numeric values differs depending on the number of bits in one word Step size of the integer part is always 1 (regardless of number of bits), and only the maximum value changes In the fraction part, the smaller the step size becomes, the error is also reduced Overflow and underflow

Precision and underflow

Overflow occurs when product is higher than the maximum value that can be represented with the exponent portion (Maximum absolute value < Overflow) Underflow occurs when product is lower than the minimum absolute value (0 < Underflow < Minimum absolute value)

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

71

Operation and Precision

Cancellation

When subtraction of 2 floating point numbers of almost equal values is performed Result becomes extremely small, it is left out of the range of numeric values which can be represented Addition of extremely small value and extremely large value is performed Exponents adjusted to the exponent of the largest value (mantissa portion of the small value is shifted largely to the right), leading to the loss of information that should have been presented

Loss of information

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

72

Non-numeric Value Representation

In order to represent characters using binary digits, codes are used

ASCII, ANSI, UNICode 0 to 9 10 types Uppercase: A to Z Lower case: a to z 52 types Symbolic keys: 40 types Control character keys: 34 types (Space key etc) Numeric keys: Character keys:

Character Representation

To assign a unique bit pattern corresponding to these 136 types of characters and symbols, 256 types of bit patterns i.e. 8 bits are used.
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 73

Non-numeric Value Representation

Character codes
o

ASCII (American Standard Code for Information Interchange) code


Character code of 8 bits (alphabet, numeric characters, etc.) Used in PCs and data transmission 7-bit character code Base of the character codes used in all countries of the world Represents 1 character with 2 bytes (16 bits)

ISO (International Organization for Standardization) code


JIS (Japanese Industrial Standard) code

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

74

Non-numeric Value Representation


o

EBCDIC (Extended Binary Coded Decimal Interchange Code)

Established to be used as standards Represents 1 character with 2 bytes 2-byte code system unified to all countries To smooth the exchange of data amongst PCs

Shift JIS (Japanese Industrial Standards) code

Unicode

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

75

Non-numeric Value Representation

Audio representation
o
o o

Multimedia audio
Audio analysis is performed using a numeric formula and once it is converted into digital codes it is processed in the computer. Word processors that accept audio input and speaker recognition are examples of its recent applications.

Image representation
o o o

Image data must be processed to support current multimedia Image data is processed as a set of dots Example
o o

1 bit is used to register the information of each dot (black, white) The representation method that combines the basic colors in each dot is used. Systems that combine the three primary colors (Red, Green and Blue) in 256 levels respectively and represent approximately 16,000,000 colors. In this case, since 8 bits are needed for 1 color, in order to register the information of 1 dot, 24 bits are used.
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 76

Information and Logic

Proposition Logic Logical operation

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

77

Proposition Logic

A proposition is an assertion that something is the case. We use sentences to express propositions. Examples:
(i) The following sentences express the same proposition: - It is raining (ii) The following sentences express the same proposition: - John loves Mary - Mary is loved by John
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 78

Proposition Logic

Proposition will always be either true or false Philosophers argue a lot about what constitutes truth. For now, we'll keep it simple:
o

"P" is true if and only if P. "P" is false if and only if not P.

Examples: (i) The proposition "Snow is white" is true if and only if snow is white. (ii) The proposition "Snow is white" is false if and only if snow is not white.
IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2 79

Proposition Logic

Truth table
Proposition 1 The wind is blowing True True Proposition 2 If the wind It is raining blows it rains True False True False

False
False

True
False

False
False

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

80

Proposition Logic

Examples
p T T F F q T F T F

p T T F F

q T F T F

p and q T F F F
81

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Logical Operation

A logical operator joins two propositions to form a new, complex, proposition. The truth value of the new proposition is determined by the truth values of the two propositions being joined and by the operator that joins them.

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

82

Logical Operation

Negation
o

Any proposition p can be converted into its negation with a negation operator, producing the new, complex, proposition:

p means Not p The proposition Not p is true if and only if p is false It is false only if p is true

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

83

Logical Operation
o

Truth tables for Negation

p T F

p F T

p T T F F

q T F T F

Not p F F T T
84

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Logical Operation

Logical Product
o

Any two propositions p and q can be connected with the conjunction AND, producing the new, complex, proposition:

p and q (p q) The proposition p and q is true if and only if both p and q are true It is false otherwise

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

85

Logical Operation
o

Truth tables for Logical product

p T T F F

q T F T F

pq T F F F
86

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Logical Operation

Logical Sum
o

Any two propositions p and q can be connected with the conjunction OR, producing the new, complex, proposition:

p or q (p q) The proposition p and q is true if and only if either p or q are true It is false only if both p and q are false

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

87

Logical Operation
o

Truth tables for Logical sum

p T T F F

q T F T F

pq T T T F

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

88

Logical Operation

Exclusive OR
o

Any two propositions p and q can be connected with the conjunction EOR, producing the new, complex, proposition:

p eor q (p q) The proposition p eor q is true only if when p or q is true It is false when both p and q are true or false

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

89

Logical Operation
o

Truth tables for Exclusive OR

p T T F F

q T F T F

p
F T T F

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

90

Logical Operation

Negative AND (NAND)


o

Any proposition p can be converted into its negation with a negation operator, producing the new, complex, proposition:

Not p The proposition Not p is true if and only if p is false It is false only if p is true

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

91

Logical Operation
o

Truth tables for Negative AND (NAND)

P T T F F

Q T F T F

P.Q T F F F

Not (P.Q) F T T T
92

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Logical Operation

Negative logical sum (NOR)


Negation of the logical sum o (p q) Summary of the truth table for the logical operations
o

Q NOT p

P AND q

P OR q

P EOR q

P NAND q

P NOR q

T T F F

T F T F

F F T T

T F F F

T T T F

F T T F

F T T T

F F F T
93

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Logical Operation

Logical expression laws


o

Logical symbols
Symbols Notation example XY + X+Y X Y
94

Meaning Negation Logical product Logical sum Exclusive OR

NOT AND

OR EOR

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Logical Operation - Laws of logical expressions


Logical product law
Logical sum law Exclusive OR law Commutative law Associative law Distributive law Absorption law Restoring law De Morgans law

X X = X, X
X + X = X, X + X X = 0, X

= 0, X 0 = 0, X 1 = X
= 1, X + 0 = X, X + 1 = 1 = 1, X 0 = X, X 1=

X + Y = Y + X, X Y = Y X X + (Y + Z) = (X + Y) + Z, X (Y Z) = (X Y) Z X + (Y Z) = (X + Y) (X + Z) X (Y + Z) = (X Y) + (X Z) X + (X Y) = X, X (X + Y) = X =X = , = +
95

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

Exercises

Use the Laws of Logical Propositions to simplify each of the propositions below to one of the propositions F, T, p, q, p.q, p+q
a) p + q + -p b) p + (q + p) + -q

IT 121: Information Technology Fundamentals 2 ICS 121: Introduction to Computer Science 2

96

Potrebbero piacerti anche