1 / 33

Binary Concepts

0 1. -- OFF. -- ON. 0 1 0 1 1 1 0 0. Binary Concepts. DATA (in binary Digits). 0 1 1 0 0 1. Main() { printf(“ Hello”); printf(“We are enjoying a world of alphapbetical coding”); }.

qamar
Download Presentation

Binary Concepts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 0 1 -- OFF -- ON 0 1 0 1 1 1 0 0 Binary Concepts DATA(in binary Digits) 0 1 1 0 0 1

  2. Main(){ printf(“ Hello”); printf(“We are enjoying a world of alphapbetical coding”); } 000111 000111010101 011101000110100101010010 01010 1010101 01001 10010001 001001 0011110 0110100 101010 10010101 101010 1010000 Data Representation

  3. In the decimal number system the successive position to the left of the decimal point represent units, tens, hundreds, thousands etc. (3 * 100) + (6*10) + (5*1) = 365 The position of the number affects its value. These kind of number systems therefore are called positional number system. The value of each digit in the number system is determined by: The digit itself The position of the digit in the number itself The base/radix of the system. (6*10) Base Position number Decimal Number System

  4. The binary number system has a base of two and symbols used are 0 and 1. In this number system, as we move to the left, the value of the digit will be two times greater than its predecessor because the base is two. Thus the value of the places are :  64  32 16 8  4  2  1 Binary Number System Binary Number 0001111001010111 Least Significant bit Most Significant bit

  5. Divide the decimal number by the base of the required number system. Note the remainder in one column and divide the quotient again with the base. Keep repeating this process until there are no numbers left to be divided. Reading of the remainder in the reverse order of them being written down will give us the required number. Now let us convert the decimal number 52 to its binary equivalent. Converting Decimal to Binary Remainder

  6. The octal system has the base of 8. The value increase from right to left as 1, 8, 64, 512, 4096. The decimal value of an octal number 1204 can be computed as : 1204 = (1 * 512) + (2 * 64) + (0 * 8) + (4 * 1)  = 512 + 128 + 0 + 4  = 644 Octal Number System

  7. Binary Octal   000 0 001 1 010 2 011 3 100             4 101 5 110             6 111             7 Octal Number System • To convert a number from binary to octal and vice versa, the following table must be kept in mind: 

  8. The binary number must be divided into groups of three from the octal point- to the right in case of the fractional portion and to the left in case of the integer portion. Each group can then be replaced with their octal equivalent. We may add zero to the left of the number if required. Converting from Binary to Octal For example : Binary 101010101010100 101 010 101 010 100  5 2 5 2 4 • 52524 is the octal equivalent of the given binary number.

  9. For example : 6         5 110 101 Similarly the binary equivalent of the octal number 65 is 110101. Converting from Octal to Binary • Each octal digit is replaced with the appropriate ‘triple’ of binary digits.

  10. Hexadecimal Decimal 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 A 10 B 11 C 12 D 13 E 14 F 15 Hexadecimal Number System • The hexadecimal number system has a base of 16, so the value increases from right to left as 1, 16, 256, 4096, 65536… • We need to keep a simple table in mind before we attempt any conversion from hexadecimal or vice-versa. • Thus the decimal equivalent of a hexadecimal number A0119 can be computed as:  = (10 * 65,536) + (0 * 4,096) + (1 * 256) + (1 * 16) + (9 * 1) = 6,55,360 + 0 + 256 + 16 + 9 =6,55,641

  11. e.g. Binary 10101011000010 Binary 0010 1010 1100 0010 Hexadecimal 2 A C 2 (From the table) Converting Binary to Hexadecimal • To convert a binary number to its hexadecimal equivalent we split the numbers into groups of four outwards, as before. Each of these groups of four are directly converted into their hexadecimal equivalent.

  12. The conversion from hexadecimal to binary consists of writing off the binary equivalent of each hexadecimal digit in groups of four. For Example: hexadecimal 1901A0412C 1 9 0 1 A 0 4 1 2 C 0001 1001 0000 0001 1010 0000 0100 0001 0010 1100 Thus the required binary number can be written as: 1100100000001101000000100000100101100 The leading zeros have been omitted. This is because it has no particular significance. It is an interesting fact that computer primary storage addressing is usually expressed in hexadecimal notation. Converting Hexadecimal to Binary

  13. คาแรกเตอร์ (ASCII)

  14. คาแรกเตอร์ (EBCDIC)

  15. คาแรกเตอร์ (Unicode)

  16. การรับค่าตัวอักษรทาง Keyboard

  17. การรับค่าตัวอักษรทางอื่น ๆ • Optical Character Recognition • Barcode Reader • Magnetic Stripe Reader • Voice Input

  18. เลขจำนวนเต็ม (Integer) • เลขจำนวนเต็มแบบที่ไม่มีเครื่องหมาย (Unsigned Integer) • กรณีไม่มีเครื่องหมาย ถ้าใช้จำนวนบิต n บิต จะแทนเลขจำนวนเต็มไม่มีเครื่องหมายได้ ตั้งแต่ 0 ถึง 2n-1 เช่น n = 16 จะแทนเลขจำนวนเต็มได้ตั้งแต่ 0 ถึง 65535 เป็นต้น

  19. เลขจำนวนเต็มแบบที่มีเครื่องหมาย (Signed Integer) 1. sign magnitude ใช้บิตซ้ายสุด (most significant bit) แทนเครื่องหมาย โดยที่ 0 แทนเครื่องหมายบวก และ 1 แทนเครื่องหมายลบ บิตที่เหลือใช้แทนขนาดของตัวเลข most significant bit least significant bit n-1 n-2 … 2 1 0 sign magnitude

  20. เลขจำนวนเต็มแบบที่มีเครื่องหมาย (Signed Integer) เช่น สมมุติว่าใช้ จำนวนบิต 8 บิต แทนเลขจำนวน +5 และ –5 ได้เป็น 00000101 และ 10000101 เป็นต้น ถ้าใช้จำนวน n บิต จะแทนเลขจำนวนเต็มแบบมีเครื่องหมาย ได้ตั้งแต่ – (2n-1 – 1) ถึง +(2n-1- 1) เช่น n = 16 จะแทนเลขจำนวนเต็มมีเครื่องหมายได้ตั้งแต่ –32767 ถึง +32767 เป็นต้น โดยที่ 0 แทนได้ทั้ง +0 และ –0

  21. เลขจำนวนเต็มแบบที่มีเครื่องหมาย (Signed Integer) 2. one complement ใช้บิตซ้ายสุด (most significant bit) แทนเครื่องหมาย โดยที่ 0 แทนเครื่องหมายบวก และ 1 แทนเครื่องหมายลบ เช่นกัน การแทนเลขบวก จะเหมือนกับแบบ sign magnitude แต่การแทนตัวเลขลบ จะต่างกัน แบบ one complement จะแทนตัวเลขลบโดยการ ทำ complement (เปลี่ยนจากเลข 0 เป็น 1 และ เปลี่ยนจากเลข 1 เป็น 0) กับ magnitude เช่น สมมุติว่าใช้ จำนวนบิต 8 บิต แทนเลขจำนวน +5 และ –5 ได้เป็น 00000101 และ 11111010 เป็นต้น

  22. เลขจำนวนเต็มแบบที่มีเครื่องหมาย (Signed Integer) ถ้าใช้จำนวน n บิต จะแทนเลขจำนวนเต็มแบบมีเครื่องหมาย ได้ตั้งแต่ – (2n-1 – 1) ถึง +(2n-1- 1) เช่น n = 16 จะแทนเลขจำนวนเต็มมีเครื่องหมายได้ตั้งแต่ –32767 ถึง +32767 เป็นต้น โดยที่ 0 แทนได้ทั้ง +0 และ –0

  23. เลขจำนวนเต็มแบบที่มีเครื่องหมาย (Signed Integer) 2. two complement ใช้บิตซ้ายสุด (most significant bit) แทนเครื่องหมาย โดยที่ 0 แทนเครื่องหมายบวก และ 1 แทนเครื่องหมายลบ เช่นกัน การแทนเลขบวก จะเหมือนกับแบบ sign magnitude แต่การแทนตัวเลขลบ จะต่างกัน แบบ two complement จะแทนตัวเลขลบโดยการ ทำ complement (เปลี่ยนจากเลข 0 เป็น 1 และ เปลี่ยนจากเลข 1 เป็น 0) กับ magnitude แล้วบวกด้วยหนึ่ง เช่น สมมุติว่าใช้ จำนวนบิต 8 บิต แทนเลขจำนวน +5 และ –5 ได้เป็น 00000101 และ 11111011 เป็นต้น

  24. เลขจำนวนเต็มแบบที่มีเครื่องหมาย (Signed Integer) ถ้าใช้จำนวน n บิต จะแทนเลขจำนวนเต็มแบบมีเครื่องหมาย ได้ตั้งแต่ – (2n-1) ถึง +(2n-1- 1) เช่น n = 16 จะแทนเลขจำนวนเต็มมีเครื่องหมายได้ตั้งแต่ –32768 ถึง +32767 เป็นต้น โดยที่ 0 แทนด้วย +0 เท่านั้น

  25. Overflow

More Related