تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39...

42
1 Copyright ©2016 Dr.Ing. Mohammed Nour Abdelgwad Ahmed as part of the course work and learning material. All Rights Reserved. Where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. CSE 100 اﻟ ﺣﺎﺳﺑﺎت و اﻟ ﺑرﻣﺟﺔ1 ﺟﺎﻣﻌﺔ اﻟزﻗﺎزﯾق ﻛﻠﯾﺔ اﻟﮭﻧدﺳﺔ ﻗﺳم ھﻧدﺳﺔ اﻟﺣﺎﺳﺑﺎت واﻟﻣﻧظوﻣﺎت د/ ﻣﺣﻣد ﻧورﻋﺑداﻟﺟواد[email protected] https://mnourgwad.github.io/CSE100 اﻟﻤﺤﺎﺿﺮة3 : داﺧﻞ اﻟﺒﯿﺎﻧﺎت ﺗﻤﺜﯿﻞ اﻟﺤﺎﺳﺐII

Upload: others

Post on 26-Apr-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

1Copyright©2016Dr.Ing.MohammedNourAbdelgwad Ahmedaspartofthecourseworkandlearningmaterial.AllRightsReserved.Whereotherwisenoted,thisworkislicensedunderaCreativeCommonsAttribution-NonCommercial-ShareAlike 4.0InternationalLicense.

CSE1001برمجة الحاسبات وال

والمنظوماتالحاسبات قسم ھندسة –الھندسةكلیة –جامعة الزقازیق

نورعبدالجوادمحمد / د[email protected]

https://mnourgwad.github.io/CSE100

IIالحاسبتمثیل البیانات داخل : 3 المحاضرة

Page 2: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

2

.العشريعداالتحویل بین األنظمة العددیة

تمثیل االرقام السالبةالعملیات الحسابیھ بالنظام الثنائي

المحاضرة الثالثھللیوم األھداف

)نقطھ المعومھال( كسریھالمثیل األعداد ت

Page 3: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

3

األخري التحویل بین األنظمھعدا العشري

Page 4: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

4

Hexadecimal

Decimal Octal

Binary

التحویل بین تلك األنظمھ العددیة

Page 5: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

5

• 8=23

• Eachgroupof3 bitsrepresentsanoctaldigit

Octal Binary

0 0 0 0

1 0 0 1

2 0 1 0

3 0 1 1

4 1 0 0

5 1 0 1

6 1 1 0

7 1 1 1

Example:

( 1 0 1 1 0 . 0 1 )2

( 2 6 . 2 )8

Assume Zeros

الثماني–التحویل الثنائي

Page 6: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

6

• 16=24

• Eachgroupof4 bitsrepresentsahexadecimaldigit

Hex Binary0 0 0 0 01 0 0 0 12 0 0 1 03 0 0 1 14 0 1 0 05 0 1 0 16 0 1 1 07 0 1 1 18 1 0 0 09 1 0 0 1A 1 0 1 0B 1 0 1 1C 1 1 0 0D 1 1 0 1E 1 1 1 0F 1 1 1 1

Example:

( 1 0 1 1 0 . 0 1 )2

( 1 6 . 4 )16

Assume Zeros

السداسي عشر–التحویل الثنائي

Page 7: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

7

• ConverttoBinary asanintermediatestep

Example:

( 0 1 0 1 1 0 . 0 1 0 )2

( 1 6 . 4 )16

Assume Zeros

( 2 6 . 2 )8

Assume Zeros

السداسي عشر–التحویل الثماني

Page 8: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

8

مثال

7058 = ?2

7 0 5

111 000 101

7058 = 1110001012

Page 9: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

9

مثال

10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112

Page 10: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

10

مثال

10768 = ?161 0 7 6

001 000 111 110

2 3 E

10768 = 23E16

Page 11: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

11

مثال

11

1F0C16 = ?81 F 0 C

0001 1111 0000 11001 7 4 1 4

1F0C16 = 174148

Page 12: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

12

شرالسداسي ع/ الثماني –التحویل من الثنائي

Page 13: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

13

تمثیل األعدادالموجبھ والسالبھ

Page 14: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

14

تمثیل األعداد الموجبة والسالبة

طرق تمثیل إشارة الرقم

االشارة والقیمةSign&Magnitude

متمم االثنین2’sComplement

متمم الواحد1’sComplement

Page 15: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

15

8 bits binary number

+7 =(0 0000111)2–7= (1 0 00 0 1 1 1)2–10=(1 0001010)2+10=(0 0001010)2

طریقة اإلشارة والقیمة

Sign 0 => +ve, 1 => –vemagnitude

Page 16: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

16

متمم الواحد: األرقام السالبة

bit 8باستخدام متمم الواحد ممثال بـ (12-)حول :مثال

8bits ==< 00001100بـ ممثلھ 12+ حول1).یتم تغییر كل بت من صفر لواحد والعكس2)

)-x-n2= x–1(:متمم الواحد

Page 17: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

17

متمم األثنین: األرقام السالبة

bit 8باستخدام متمم األثنین ممثال بـ (12-)حول :مثالالحل

8bits ==< 00001100بـ ممثلھ 12+ حول1).یتم تغییر كل بت من صفر لواحد والعكس2)1یتم جمع 3)

)-x-n2= x( : متمم األثنین

Page 18: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

18

n-bitفي حالة لدینا

التي تستطیع) األرقام(من القیم ما ھو المديتمثیلھ؟

Page 19: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

19

مدي تمثیل األرقام الموجیھ والسالبھ

أكبر رقم سالب موجب أكبر رقم

-(2n-1-1) (2n-1-1) و القیمھ األشارهSign&Mag.

-(2n-1-1) (2n-1-1) متمم الواحد1’sComp.

-(2n-1) (2n-1-1) متمم األثنین2’sComp.

Page 20: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

20

العملیات الحسابیھبالنظام الثنائي

Page 21: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

21

)متمم األثنین/(الطرح -الجمع:B+Aخطوات الجمع §

قم بالجمع الثنائي للرقمین1.

یتم إھمال الباقي إذا وجد2.

–A: خطوات الطرح§ B=A+(–B)

من خالل Bبالحصول علي متمم االثنین للرقم قم 1.1إضافةقیمة كل خانھ ثم قلب

.Aإلي Bقم بجمع متمم االثنین الخاص بـ 2.

Page 22: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

22

:.comps’2العملیة باستخدام

0 0 11101111 0 −0011 0 01

177=

23=

(-23)=

00

+1

1 010110

1001011+

1

Page 23: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

23

)متمم األثنین/(الطرح -الجمع

بت 4قم بإجراء العملیات الحسابیھ التالیھ ممثلھ بـ : أمثلھ§+3 0011

+ +4 + 0100---- ------+7 0111

-2 1110+ -6 + 1010---- --------8 11000

+6 0110+ -3 + 1101---- ------+3 10011

+4 0100+ -7 + 1001---- --------3 1101

Page 24: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

24

)متمم الواحد/(الطرح -الجمع

:B+Aخطوات الجمع §قم بالجمع الثنائي للرقمین1..قم بإضافة الباقي إذا وجد علي الناتج2.

–Aخطوات الطرح§ B=A– B=A+(–B).من خالل قلب كل خانھ Bقم بالحصول علي متمم الواحد لـ 1..Aإلي Bبجمع متمم الواحد الخاص بـ قم 2.

Page 25: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

25

)متمم الواحد/(الطرح -الجمع

+3 0011+ +4 + 0100---- -------

+7 0111

+5 0101+ -5 + 1010---- -------

-0 1111

-2 1101+ -5 + 1010---- ------

-7 10111---- + 1

------1000

-3 1100+ -7 + 1000---- --------10 10100

---- + 1-------

0101

بت 4قم بإجراء العملیات الحسابیة التالیة ممثلھ بـ : أمثلھ§

Page 26: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

26

الكسریھتمثیل األعداد )النقطھ المعومھ(

Page 27: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

27

األعداد الكسریةتمثیل

1:مثال

2

3

4

1256.3= 125.63 X 10 = 12.563 X 10 = 1.2563 X 10 = 0.12563 X 10

إشارة الرقم+

ھتمثیل األس بإشارت+4

قیمة الرقم12563

Sign ofmantissa

Exponent Mantissa

Page 28: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

28

:تمثیل األعداد الكسریھ)Floating Point(طریقة النقطھ المعومھ

:مثال+0.10111x2+3

0 00011 101110000

Sign ofmantissa

Exponent(5bits)

Mantissa(9bits)

Page 29: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

29

:تمثیل األعداد الكسریھ)Floating Point(طریقة النقطھ المعومھ

:مثال-0.10111x2-3

1 11101 101110000

Sign ofmantissa

Exponent(5bits)

Mantissa(9bits)

Page 30: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

30

:تمثیل األعداد الكسریھ)Floating Point(طریقة النقطھ المعومھ

Page 31: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

31

:تمثیل األعداد الكسریھ

0.125= وبناء علیھ فإن الخطأ المطلق 100.25قیمة العدد الممثل ھي

:لتحسین ذلك الخطأØ6بدال من 5 عدد خانات األس لتصبح نقترح تخفیضØ9بدال من 10ثم زیادة عدد خانات تمثیل الرقم لتصبح

Page 32: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

32

BCDANDASCIICODE

Page 33: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

33

BinaryCodes

§“Ann-bitbinarycodeisagroupofn bitsthatassumeupto2n distinctcombinationsof1sand0s,witheachcombinationrepresentingoneelementofthesetbeingcoded”

§Forthe10digitsneeda4bitcode.OnecodeiscalledBinaryCodedDecimal(BCD)

Page 34: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

34

BinaryCodedDecimal(BCD)

§TheBCDissimplythe4bitrepresentationofthedecimaldigit.

§Formultipledigitbase10numbers,eachsymbolisrepresentedbyitsBCDdigit

§Whathappenedto6digitsnotused?

Page 35: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

35

•BCDfor417to195(417)10 =(0100 00010111)BCD

(195)10 =(000110010101)BCD

BinaryCodedDecimal(BCD)

Page 36: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

36

AlphanumericCodes

Howdoyouhandlealphanumericdata?§Formulateabinarycodetorepresentcharacters!J

§Forthe26letterofthealphabetwouldneed5bitforrepresentation.

§Butwhatabouttheuppercaseandlowercase,andthedigits,andspecialcharacters

Page 37: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

37

AcodecalledASCII

§ASCIIstandsforAmericanStandardCodeforInformationInterchange

§Thecodeuses7bitstoencode128uniquecharacters

Asanote,formally,worktocreatethiscodebeganin1960.1ststandardin1963.Lastupdatedin1986.

Page 38: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

38

Page 39: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

39

ASCIICode

§Representsthenumbers• Allstart011xxxx andthexxxx istheBCDforthedigit

§Representthecharactersofthealphabet• Startwitheither100,101,110,or111

§Afewspecial charactersareinthisarea• Startwith010– spaceand!”#$%&’()*+.-,/• Startwith000or001– controlcharlikeESC

Page 40: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

40

ASCIIExample

§Encodingof123011000101100100110011

§EncodingofJoanne100101011011111100001110111011011101100101

§Notethattheseare7bitcodes

Page 41: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

41

Whattodowiththe8th Bit?

§Indigitalsystemsdataisusuallyorganizedasbytesor8bitofdata.

§Howaboutusingthe8thbitforanerrorcoding.Thiswouldhelpduringdatatransmission,etc.

§Paritybit– theextrabitincludedtomakethetotalnumberof1sinthebyteeitherevenorodd– calledevenparityandoddparity

Page 42: تﺎﻣوظﻧﻣﻟاو تﺎﺑﺳﺎﺣﻟا 1 ﺔﺟﻣرﺑﻟاو ... · 2020-03-03 · 39 ASCII Code §Represents the numbers • All start 011 xxxx and the xxxxis the BCD

42

ExampleofParity

§Considerdata 1000001• EvenParity 01000001• OddParity 1100 0001

§Considerdata1010100• EvenParity 11010100• OddParity 01010100

§AparitycodecanbeusedforASCIIcharactersandanybinarydata.