8 number-system

68
Number System

Upload: rohit-shrivastava

Post on 15-Apr-2017

258 views

Category:

Internet


0 download

TRANSCRIPT

Page 1: 8 number-system

Number System

Page 2: 8 number-system

05/03/232

Page 3: 8 number-system

05/03/233

Page 4: 8 number-system

05/03/234

Page 5: 8 number-system

05/03/235

Page 6: 8 number-system

05/03/236

Page 7: 8 number-system

05/03/237

Page 8: 8 number-system

05/03/238

Page 9: 8 number-system

05/03/239

Page 10: 8 number-system

05/03/2310

Page 11: 8 number-system

05/03/2311

Page 12: 8 number-system

05/03/2312

Page 13: 8 number-system

05/03/2313

Page 14: 8 number-system

05/03/2314

Page 15: 8 number-system

05/03/2315

Page 16: 8 number-system

05/03/2316

Page 17: 8 number-system

05/03/2317

Page 18: 8 number-system

05/03/2318

Page 19: 8 number-system

05/03/2319

Page 20: 8 number-system

05/03/2320

Page 21: 8 number-system

05/03/2321

Page 22: 8 number-system

05/03/2322

Page 23: 8 number-system

05/03/2323

Page 24: 8 number-system

05/03/2324

Page 25: 8 number-system

05/03/2325

Page 26: 8 number-system

05/03/2326

Page 27: 8 number-system

05/03/2327

Page 28: 8 number-system

05/03/2328

Page 29: 8 number-system

05/03/2329

Page 30: 8 number-system

05/03/2330

Page 31: 8 number-system

05/03/2331

Page 32: 8 number-system

05/03/2332

Page 33: 8 number-system

r’s and r-1’s COMPLEMENTS USED FOR

SIMPLIFY SUBTRACTION OPERATIONS

TWO TYPES Decimal Binary Octal Hexadecimal

r’ s complement 10’s 2’s 8’s 16’s r - 1’s complement 9’s 1’s 7’s 15’sHere r is base or radix of number system

r’s Complement LEAVE ALL LSD ZEROS UNCHANGED SUBSTRACT FIRST NONZERO LSD FROM r SUBSTRACT ALL OTHER HIGHER DIGITS FROM r-1

r-1’s Complement SUBSTRACT EVERY DIGIT FROM r-1

Note: r’s Complement=r-1’s Complement +1

Page 34: 8 number-system

34

RULES TO GET COMPLEMENTS9’S

SUBSTRACT EVERY DIGIT FROM 9 Example: 9’s complement of 134795 is 865204

10’s=(9’s complement +1)10’s complement can be Directly calculated by following steps:

LEAVE ALL LSD ZEROS UNCHANGED SUBSTRACT FIRST NONZERO LSD FROM 10 SUBSTRACT ALL OTHER HIGHER DIGITS FROM 9 Example:10’s complement of 134795 is 865205 Example: find the 9’s and 10’s complements of 314700.

2’S LEAVE ALL LS ZEROS AND FIRST NON ZERO DIGIT UNCHANGED REPLACE 1 BY 0 AND 0 BY 1 IN ALL HIGHER DIGITS

1’S 1 IS CHANGED TO 0 AND 0 IS CHANGED TO 1

Note: COMPLEMENT OF A COMPLEMENT RESTORES THE ORIGINAL VALUE OF THE NUMBER

Page 35: 8 number-system

10’s Complement Examples

35

-003

+1

996

997

-214

+1

785

786

Example #1

Example #2

Complement Digits

Add 1

Complement Digits

Add 1

Page 36: 8 number-system

Subtraction using r’s complement:

To find M-N in base r, we add M + r’s complement of N

1) If M > N then result is M – N + c (c is an end around carry and

Just neglect it. 2) If M < N then result is rn –(N-M) which is the

r’s complement of the result. (to get actual number take r’s

complement again and put – sign before number)

05/03/2336

Page 37: 8 number-system

Example

05/03/2337

Page 38: 8 number-system

Subtraction using r-1’s complement

The same rules apply to subtraction using the (r-1)’s complements.

The only difference is that when an end carry is generated, it is not discarded but added to the least significant digit of the result.

Also, if no end carry is generated, then the answer is negative and in the (r-1)’s complement form.

05/03/2338

Page 39: 8 number-system

05/03/2339

Page 40: 8 number-system

05/03/2340

Page 41: 8 number-system

05/03/2341

Page 42: 8 number-system

05/03/2342

Page 43: 8 number-system

05/03/2343

Page 44: 8 number-system

BINARY ARITHMETIC OPERATION

05/03/2344

Page 45: 8 number-system

BINARY ADDITION EXAMPLE

05/03/2345

Page 46: 8 number-system

BINARY ARITHMETIC OPERATION (Cont…)

05/03/2346

We have already discussed these two.

Page 47: 8 number-system

BINARY SUBTRACTION EXAMPLE

05/03/2347

Page 48: 8 number-system

05/03/2348

Page 49: 8 number-system

OCTAL ARITHMETIC OPERATION

05/03/2349

Page 50: 8 number-system

05/03/2350

Page 51: 8 number-system

05/03/2351

Page 52: 8 number-system

05/03/2352

Page 53: 8 number-system

05/03/2353

Page 54: 8 number-system

05/03/2354

Page 55: 8 number-system

05/03/2355

Page 56: 8 number-system

05/03/2356

Page 57: 8 number-system

05/03/2357

Page 58: 8 number-system

05/03/2358

Flowchart for steps in C program Execution

Page 59: 8 number-system

Practice problems 1. Given the binary number 11011011, what is its

decimal value if it is aa.unsigned binary numberb.Signed binary numberc.2's complement number

2. Convert +24 into a 2's complement number

05/03/2359

Ans: 219Ans: -37

Ans: -37

Ans: 011000 Note the leading zero!

Page 60: 8 number-system

3. Convert -24 into a 2's complement number

4. Convert -1 into a 2's complement number (assume a 4-bit result)

5. What is the minimum (maximum negative) number which can be

represented using a 6-bit 2's Complement representation? What is the maximum (positive) number?

05/03/2360

Ans: 1111

Ans: 101000

Ans: +31, -32

Practice problems (Cont…)

Page 61: 8 number-system

Practice problems (Cont…)

Convert, if possible, the following decimal numbers to 2's complement assuming an 8-bit binary representation for all.

i. 1 = ii. -1 =iii. 72 = iv. 127 =v. -127 = 10000001 vi. -105 = 10010111vii. 255 = viii. -255 = ix. -6 =

05/03/2361

00000001 1111111101001000 01111111

Not Possible 11111010

Not Possible

Page 62: 8 number-system

Practice problems (Cont…)

Convert the following 2's complement numbers to decimal.

i. 1111 = ii. 11110000 =iii. 001101 = iv. 11111111

= -1v. 0000000 = 0 vi. 01 = 1

05/03/2362

-1 -1613

Page 63: 8 number-system

05/03/2363

Page 64: 8 number-system

05/03/2364

Page 65: 8 number-system

As a general rule, it is a good idea to avoid the use operators that cause side effects inside of compound expressions. This includes all assignment operators, plus the increment and decrement operators.

05/03/2365

Note: As a general rule, it is a good idea to avoid the use of operators that alter the value of same variable more than one in the same expression, because this causes side effects. This includes all assignment operators, plus the increment and decrement operators.For all side effects result will be compiler dependent.

Page 66: 8 number-system

05/03/2366

Page 67: 8 number-system

#include<stdio.h>void main() {

int i=3;printf("%d",++i + ++i); o/p 9 for turbo c

10 by codepad} The results are undefined. You're modifying a variable more

than once in an expression (or sequence point to be more accurate).

Modifying a variable more than once between sequence points is undefined, so don't do it.

05/03/2367

Page 68: 8 number-system

05/03/2368