Appendix. Bit Operators

Size: px
Start display at page:

Download "Appendix. Bit Operators"

Transcription

1 Appendix C Bit Operations C++ operates with data entities, such as character, integer, and double-precision constants and variables, that can be stored as 1 or more bytes. In addition, C++ provides for manipulating bits of character and integer constants and variables. Generally, these bit manipulations are used in computer science and engineering applications and typically aren t required in commercial applications. The operators used to perform bit manipulations are called bit operators and are listed in Table C.1. Table C.1 Operator & ^ ~ << >> Bit Operators Description Bit-by-bit AND Bit-by-bit inclusive OR Bit-by-bit exclusive OR Bit-by-bit ones complement Left shift Right shift

2 C-2 Bit Operations All the operators listed in Table C.1, except ~, are binary operators, requiring two operands. Each operand is treated as a binary number consisting of a series of 1s and 0s. The bits in each operand are then compared on a bit-by-bit basis, and the result is determined based on the selected operation. The AND Operator The AND operator, &, causes a bit-by-bit AND comparison between its two operands. The result of each bit-by-bit comparison is a 1 only when both bits being compared are 1s; otherwise, the result of the AND operation is a 0. For example, the following two 8-bit numbers are to be ANDed: 1ƒ0ƒ1ƒ1ƒ0ƒ0ƒ1ƒ1 1ƒ1ƒ0ƒ1ƒ0ƒ1ƒ0ƒ1 ƒ ƒ ƒ ƒ ƒ ƒ ƒ To perform an AND operation, each bit in one operand is compared with the bit occupying the same position in the other operand. The following sample AND operation illustrates the correspondence between bits for these two operands: ƒƒ1ƒ0ƒ1ƒ1ƒ0ƒ0ƒ1ƒ1 &ƒ1ƒ1ƒ0ƒ1ƒ0ƒ1ƒ0ƒ1 ƒƒ ƒ ƒ ƒ ƒ ƒ ƒ ƒ ƒƒ1ƒ0ƒ0ƒ1ƒ0ƒ0ƒ0ƒ1 As shown, when both bits being compared are 1s, the result is a 1; otherwise, the result is a 0. The result of each comparison is, of course, independent of any other bit comparison. Program C.1 shows the use of an AND operation. In this program, the variable op1 is initialized to the octal value 325, which is the octal representation of the binary number , and the variable op2 is initialized to the octal value 263, which is the octal representation of the binary number They re the same two binary numbers used in the preceding example. Program C.1 #includeƒ<iostream> usingƒnamespaceƒstd; intƒmain() ƒƒintƒop1ƒ=ƒ0325,ƒop2ƒ=ƒ0263; ƒƒintƒop3ƒ=ƒop1ƒ&ƒop2; ƒƒcoutƒ<<ƒoctƒ<<ƒop1ƒ<<ƒ ƒandedƒwithƒ <<ƒop2ƒ<<ƒ ƒisƒ ƒ<<ƒop3ƒ<<ƒendl; ƒƒreturnƒ0;

3 Appendix C C-3 Program C.1 produces the following output: 325ƒANDedƒwithƒ263ƒisƒ221 The result of ANDing the octal numbers 325 and 263 is the octal number 221. The binary equivalent of 221 is the binary number , which is the result of the AND operation shown previously. AND operations are useful for masking, or eliminating, selected bits from an operand. The reason is that ANDing any bit (1 or 0) with a 0 forces the resulting bit to be a 0, and ANDing any bit (1 or 0) with a 1 leaves the original bit unchanged. For example, say the variable op1 has the bit pattern xƒxƒxƒxƒxƒxƒxƒx, in which each x can be 1 or 0, independent of any other x in the number. The result of ANDing this binary number with the binary number is as follows: ƒƒƒop1ƒ=ƒƒƒxƒxƒxƒxƒxƒxƒxƒx ƒƒƒop2ƒ=ƒƒƒ0ƒ0ƒ0ƒ0ƒ1ƒ1ƒ1ƒ1 ƒƒƒƒƒƒƒƒƒƒƒ ƒ ƒ ƒ ƒ ƒ ƒ ƒ- Resultƒ=ƒƒƒ0ƒ0ƒ0ƒ0ƒxƒxƒxƒx As you can see in this example, the 0s in op2 mask the bits in op1, and the 1s in op2 filter, or pass, the bits in op1 through with no change in their values. In this example, the variable op2 is called a mask. By choosing the mask appropriately, any bit in an operand can be selected, or filtered, out of an operand for inspection. For example, ANDing the variable op1 with the mask forces all bits of the result to be 0, except the third bit. The third bit of the result is a copy of the third bit of op1. Therefore, if the result of the AND operation is 0, the third bit of op1 must have been 0, and if the result of the AND is a non-zero number, the third bit must have been 1. Program C.2 uses this masking property to convert lowercase letters into their uppercase form, assuming the letters are stored with the ASCII code. The algorithm for converting letters is based on binary codes for lowercase and uppercase letters in ASCII being the same except for bit five, which is a 1 for lowercase letters and a 0 for uppercase letters. 1 For example, the binary code for the letter a is (hex 61), and the binary code for the letter A is (hex 41). Similarly, the binary code for the letter z is (hex 7A), and the binary code for the letter Z is (hex 5A). (See Appendix B in the book for the hexadecimal values of uppercase and lowercase letters.) Therefore, a lowercase letter can be converted into its uppercase form by forcing the fifth bit to 0. Program C.2 does this by masking the letter s code with the binary value , which has the hexadecimal value DF. 1 This algorithm assumes the conventional numbering scheme, starting with bit 0 as the rightmost bit, is used. With this convention, the rightmost bit (bit 0) is referred to as the least significant bit (LSB), and the leftmost bit is referred to as the most significant bit (MSB). In this example, the MSB is bit 7.

4 C-4 Bit Operations Program C.2 #includeƒ<iostream> usingƒnamespaceƒstd; constƒintƒto_upƒ=ƒ0xdf; constƒintƒmaxƒ=ƒ80; intƒmain() ƒƒƒcharƒword[max];ƒƒƒƒƒƒƒ//ƒenoughƒstorageƒforƒaƒcompleteƒline ƒƒƒvoidƒupper(charƒ*);ƒƒƒ//ƒfunctionƒprototype ƒƒƒcoutƒ<<ƒ Enterƒaƒstringƒofƒbothƒupperƒandƒlowercaseƒletters:\n ; ƒƒƒcin.getline(word,max,'\n'); ƒƒƒcoutƒ<<ƒ \ntheƒstringƒofƒlettersƒjustƒenteredƒis:\n ƒƒƒƒƒƒƒƒ<<ƒwordƒ<<ƒendl; ƒƒƒupper(word); ƒƒƒcoutƒ<<ƒ \nthisƒstringƒinƒuppercaseƒlettersƒis:\n ƒƒƒƒƒƒƒƒ<<ƒwordƒ<<ƒendl; ƒƒƒreturnƒ0; voidƒupper(charƒ*word) ƒƒwhileƒ(*wordƒ!=ƒ'\0') ƒƒƒƒ*word++ƒ&=ƒto_up; ƒƒreturn; A sample run of Program C.2 follows: Enterƒaƒstringƒofƒbothƒupperƒandƒlowercaseƒletters: abcdefghijklmnopqrstuvwxyz Theƒstringƒofƒlettersƒjustƒenteredƒis: abcdefghijklmnopqrstuvwxyz Thisƒstringƒinƒuppercaseƒlettersƒis: ABCDEFGHIJKLMNOPQRSTUVWXYZ Notice that lowercase letters are converted to uppercase form, and uppercase letters are unaltered. This result happens because bit five of all uppercase letters is 0, so forcing this bit to 0 with the mask has no effect. Only when bit five is 1, as for lowercase letters, is the input character altered.

5 Appendix C C-5 The Inclusive OR Operator The inclusive OR operator,, performs a bit-by-bit comparison of its two operands in a similar fashion as the bit-by-bit AND. The result of the OR comparison, however, is determined by the following rule: The result of the comparison is 1 if either bit being compared is a 1; otherwise, the result is a 0. You can see this rule in the following sample OR operation. As with all bit operations, the result of each comparison is independent of any other comparison. ƒƒ1ƒ0ƒ1ƒ1ƒ0ƒ0ƒ1ƒ1 ƒ1ƒ1ƒ0ƒ1ƒ0ƒ1ƒ0ƒ1 ƒƒ ƒ ƒ ƒ ƒ ƒ ƒ ƒ ƒƒ1ƒ1ƒ1ƒ1ƒ0ƒ1ƒ1ƒ1 Program C.3 shows the use of an OR operation, using the octal values of the operands in the preceding example. Program C.3 #includeƒ<iostream> usingƒnamespaceƒstd; intƒmain() ƒƒintƒop1ƒ=ƒ0325,ƒop2ƒ=ƒ0263; ƒƒintƒop3ƒ=ƒop1ƒ ƒop2; ƒƒcoutƒ<<ƒoctƒ<<ƒop1ƒ<<ƒ ƒoredƒwithƒ ƒ<<ƒop2ƒ<<ƒ ƒisƒ ƒ<<ƒop3ƒ<<ƒendl; ƒƒreturnƒ0; Program C.3 produces the following output: 325ƒORedƒwithƒ263ƒisƒ367 The result of ORing the octal numbers 325 and 263 is the octal number 367. The binary equivalent of 367 is , which is the result of the OR operation shown previously. Inclusive OR operations are useful for forcing selected bits to take on a 1 value or for passing through other bit values unchanged. The reason is that ORing any bit (1 or 0) with a 1 forces the resulting bit to be a 1, and ORing any bit (1 or 0) with a 0 leaves the original bit unchanged. For example, the variable op1 has the bit pattern xƒxƒxƒxƒxƒxƒxƒx; each x can be 1 or 0, independent of any other x in the number. The result of ORing this binary number with the binary number is as follows: ƒƒƒop1ƒ=ƒƒƒxƒxƒxƒxƒxƒxƒxƒx ƒƒƒop2ƒ=ƒƒƒ1ƒ1ƒ1ƒ1ƒ0ƒ0ƒ0ƒ0 ƒƒƒƒƒƒƒƒƒƒƒ ƒ ƒ ƒ ƒ ƒ ƒ ƒ- Resultƒ=ƒƒƒ1ƒ1ƒ1ƒ1ƒxƒxƒxƒx

6 C-6 Bit Operations As you can see in this example, the 1s in op2 force the resulting bits to 1, and the 0s in op2 filter, or pass, the bits in op1 through with no change in their values. By using an OR operation, you can produce a masking operation similar to an AND operation, except the masking bits are set to 1s rather than 0s. Another way of looking at it is to say that ORing with a 0 has the same effect as ANDing with a 1. Program C.4 uses this masking property to convert uppercase letters in a word into their lowercase form by masking the letter s code with the binary value , which has the hexadecimal value 20. Program C.4 #includeƒ<iostream>ƒ usingƒnamespaceƒstd; constƒintƒmaxƒ=ƒ80; constƒintƒto_lowƒ=ƒ0x20; intƒmain() ƒƒcharƒword[max];ƒƒƒƒƒƒ//ƒenoughƒstorageƒforƒaƒcompleteƒline ƒƒvoidƒlowerƒ(charƒ*);ƒ//ƒfunctionƒprototype ƒƒcoutƒ<<ƒ Enterƒaƒstringƒofƒbothƒupperƒandƒlowercaseƒletters:\n ; ƒƒcin.getline(word,max,'\n'); ƒƒcoutƒ<<ƒ \ntheƒstringƒofƒlettersƒjustƒenteredƒis:\n ƒƒƒƒƒƒƒ<<ƒwordƒ<<ƒendl; ƒƒlower(word); ƒƒcoutƒ<<ƒ \nthisƒstringƒinƒlowercaseƒlettersƒis:\n ƒƒƒƒƒƒƒ<<ƒwordƒ<<ƒendl; ƒƒreturnƒ0; voidƒlower(charƒ*word) ƒƒwhileƒ(*wordƒ!=ƒ'\0') ƒƒƒƒ*word++ƒ =ƒto_low;ƒ ƒƒreturn;

7 Appendix C C-7 A sample run of Program C.4 follows. Enterƒaƒstringƒofƒbothƒupperƒandƒlowercaseƒletters: abcdefghijklmnopqrstuvwxyz Theƒstringƒofƒlettersƒjustƒenteredƒis: abcdefghijklmnopqrstuvwxyz Thisƒstringƒinƒlowercaseƒlettersƒis: abcdefghijklmnopqrstuvwxyz Notice that uppercase letters are converted to lowercase form, and lowercase letters are unaltered. This result happens because bit five of all lowercase letters is 1, so forcing this bit to 1 with the mask has no effect. Only when bit five is 0, as for uppercase letters, is the input character altered. The Exclusive OR Operator The exclusive OR operator, ^, performs a bit-by-bit comparison of its two operands. The result of the comparison is determined by the following rule: The result of the comparison is 1 if one, and only one, of the bits being compared is a 1; otherwise, the result is 0. The following example of an exclusive OR operation shows that when both bits being compared are the same value (both 1 or both 0), the result is 0. Only when both bits have different values (one bit a 1 and the other a 0) is the result 1. Again, each pair or bit comparison is independent of any other bit comparison. ƒƒ1ƒ0ƒ1ƒ1ƒ0ƒ0ƒ1ƒ1 ^ƒ1ƒ1ƒ0ƒ1ƒ0ƒ1ƒ0ƒ1 ƒƒ ƒ ƒ ƒ ƒ ƒ ƒ ƒ ƒƒ0ƒ1ƒ1ƒ0ƒ0ƒ1ƒ1ƒ0 An exclusive OR operation can be used to create the opposite value, or complement, of any bit in a variable. The reason is that exclusive ORing any bit (1 or 0) with 1 forces the resulting bit to be the opposite value of its original state, and exclusive ORing any bit (1 or 0) with 0 leaves the original bit unchanged. For example, the variable op1 has the bit pattern xƒxƒxƒxƒxƒxƒxƒx; each x can be 1 or 0, independent of any other x in the number. Using the notation that x is the complement (opposite) value of x, the result of exclusive ORing this binary number with the binary number is as follows: ƒƒƒop1ƒ=ƒƒƒxƒxƒxƒxƒxƒxƒxƒx ƒƒƒop2ƒ=ƒƒƒ0ƒ1ƒ0ƒ1ƒ0ƒ1ƒ0ƒ1 ƒƒƒƒƒƒƒƒƒƒƒ ƒ ƒ ƒ ƒ ƒ ƒ ƒƒƒƒƒƒƒƒƒƒƒƒƒƒ_ƒƒƒ_ƒƒƒ_ƒƒƒ_ Resultƒ=ƒƒƒxƒxƒxƒxƒxƒxƒxƒx As you can see in this example, the 1s in op2 force the resulting bits to be the complement of their original bit values, and the 0s in op2 filter, or pass, the bits in op1 through with no change in their values.

8 C-8 Bit Operations Many encryption methods use the exclusive OR operation to code data by exclusive ORing each character in the string with a mask value. The choice of the mask value, which is referred to as the encryption key, is arbitrary, and any key value can be used. Program C.5 uses an encryption key of 52 to code a user-entered message. Program C.5 #includeƒ<iostream> usingƒnamespaceƒstd; constƒintƒmaxƒ=ƒ80; intƒmain() ƒƒcharƒmessage[max];ƒƒƒƒƒ//ƒenoughƒstorageƒforƒaƒcompleteƒline ƒƒvoidƒencrypt(charƒ*);ƒƒ//ƒfunctionƒprototype ƒƒcoutƒ<<ƒ \nenterƒaƒsentence:\n ; ƒƒcin.getline(message,max,'\n'); ƒƒcoutƒ<<ƒ \ntheƒsentenceƒjustƒenteredƒis:\n ƒƒƒƒƒƒƒ<<ƒmessageƒ<<ƒendl; ƒƒencrypt(message); ƒƒcoutƒ<<ƒ \ntheƒencryptedƒversionƒofƒthisƒsentenceƒis:\n ƒƒƒƒƒƒƒ<<ƒmessageƒ<<ƒendl; ƒƒreturnƒ0; voidƒencrypt(charƒ*message) ƒƒwhileƒ(*messageƒ!=ƒ'\0') ƒƒƒƒƒ*message++ƒ^=ƒ52; ƒƒreturn; Following is a sample run of Program C.5: Enterƒaƒsentence: Good morning Theƒsentenceƒjustƒenteredƒis: Goodƒmorning Theƒencryptedƒversionƒofƒthisƒsentenceƒis: s[[p Y[FZ]ZS

9 Appendix C C-9 Decoding an encrypted message requires exclusive ORing the coded message with the original encryption key. The Complement Operator The complement operator, ~, is a unary operator that changes each 1 bit in its operand to 0 and each 0 bit to 1. For example, if the variable op1 contains the binary number , ~op1 replaces this binary number with the number The complement operator is used to force any bit in an operand to 0, independent of the actual number of bits used to store the number. For example, the statement op1ƒ=ƒop1ƒ&ƒ~07;ƒƒƒ//ƒ07ƒisƒanƒoctalƒnumber or its shorter form op1ƒ&=ƒ~07;ƒƒƒ//ƒ07ƒisƒanƒoctalƒnumber sets the last three bits of op1 to 0, regardless of how op1 is stored in the computer. Either statement can, of course, be replaced by ANDing the last three bits of op1 with 0s, if the number of bits used to store op1 is known. In a computer that uses 16 bits to store integers, the AND operation is op1ƒ=ƒop1ƒ&ƒ ;ƒƒƒ//ƒinƒoctal or op1ƒ=ƒop1ƒ&ƒ0xfff8;ƒƒƒ//ƒinƒhexadecimal For a computer that uses 32 bits to store integers, the preceding AND operation also sets the leftmost or higher order 16 bits to 0, which is an unintended result. The following is the correct statement for 32 bits: op1ƒ=ƒop1ƒ&ƒ ;ƒƒƒ//ƒinƒoctal or op1ƒ=ƒop1ƒ&ƒ0xfffffff8;ƒƒƒ//ƒinƒhexadecimal Using the complement operator in this situation frees the programmer from having to determine the operand s storage size and, more important, makes the program portable between machines using different integer storage sizes. Different-Sized Data Items When the bit operators &,, and ^ are used with operands of different sizes, the shorter operand is always increased in bit size to match the larger operand s size. Figure C.1 illustrates extending a 16-bit unsigned integer into a 32-bit number. As the figure shows, the extra bits are added to the left of the original number and filled with 0s. This is the equivalent of adding leading 0s to the number, which has no effect on the number s value.

10 C-10 Bit Operations 16 bits XXXXXXXXXXXXXXXX X can be 1 or s The original 16 bits XXXXXXXXXXXXXXXX 32 bits Figure C.1 Extending 16-bit unsigned data to 32 bits When extending signed numbers, the original leftmost bit is reproduced in the extra bits added to the number. As shown in Figure C.2, if the original leftmost bit is 0, corresponding to a positive number, 0 is placed in each of the additional bit positions. If the leftmost bit is 1, which corresponds to a negative number, 1 is placed in the additional bit positions. In either case, the resulting binary number has the same sign and magnitude as the original number. 16 bits A sign bit of s 0XXXXXXXXXXXXXXX The original 16 bits X can be 1 or XXXXXXXXXXXXXXX 16 bits A sign bit of 1 1XXXXXXXXXXXXXXX 16 1s The original 16 bits XXXXXXXXXXXXXXX Figure C.2 Extending 16-bit signed data to 32 bits The Shift Operators The left shift operator, <<, causes the bits in an operand to be shifted to the left by a given amount. For example, the statement op1ƒ=ƒop1ƒ<<ƒ4;

11 Appendix C C-11 causes the bits in op1 to be shifted four bit positions to the left, filling any vacated bits with a 0. Figure C.3 illustrates the effect of shifting the binary number to the left by four bit positions Each bit is shifted to the left by the designated number of places Vacated bit positions are filled with 0s Figure C.3 An example of a left shift For unsigned integers, each left shift corresponds to multiplication by 2. This is also true for signed numbers using twos complement representation, as long as the leftmost bit doesn t switch values. Because a change in the leftmost bit of a twos complement number represents a change in both the sign and magnitude represented by the bit, this shift doesn t represent a simple multiplication by 2. The right shift operator, >>, causes the bits in an operand to be shifted to the right by a given amount. For example, the statement op2ƒ=ƒop1ƒ>>ƒ3; causes the bits in op1 to be shifted to the right by three bit positions. Figure C.4a shows the right shift of the unsigned binary number by three bit positions. As shown, the three rightmost bits are shifted off the end and are lost.

12 C-12 Bit Operations Each bit is shifted to the right by the designated number of places Vacated bit positions are filled with 0s Figure C.4a An unsigned arithmetic right shift For unsigned numbers, the leftmost bit isn t used as a sign bit. For this type of number, the vacated leftmost bits are always filled with 0s, as shown in Figure C.4a. For signed numbers, what s filled in the vacated bits depends on the computer. Most computers reproduce the number s original sign bit. Figure C.4b illustrates the right shift of a negative binary number by four bit positions, and the sign bit is reproduced in the vacated bits. Figure C.4c illustrates the equivalent right shift of a positive signed binary number. The sign bit is a Each bit is shifted to the right by the designated number of places Vacated bit positions are filled with 1s Figure C.4b The right shift of a negative binary number

13 Appendix C C-13 The sign bit is a Each bit is shifted to the right by the designated number of places Vacated bit positions are filled with 0s Figure C.4c The right shift of a positive binary number The type of fill shown in Figures C.4b and C.4c, where the sign bit is reproduced in vacated bit positions, is called an arithmetic right shift. In an arithmetic right shift, each single shift to the right corresponds to a division by 2. Instead of reproducing the sign bit in right-shifted signed numbers, some computers fill the vacated bits with 0s automatically. This type of shift is called a logical shift. For positive signed numbers, in which the leftmost bit is 0, both arithmetic and logical right shifts produce the same result. The results of these two shifts are different only when negative numbers are involved.

Number System. Introduction. Decimal Numbers

Number System. Introduction. Decimal Numbers Number System Introduction Number systems provide the basis for all operations in information processing systems. In a number system the information is divided into a group of symbols; for example, 26

More information

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems Decimal & Binary Representation Systems Decimal & binary are positional representation systems each position has a value: d*base i for example: 321 10 = 3*10 2 + 2*10 1 + 1*10 0 for example: 101000001

More information

Chapter 4. Operations on Data

Chapter 4. Operations on Data Chapter 4 Operations on Data 1 OBJECTIVES After reading this chapter, the reader should be able to: List the three categories of operations performed on data. Perform unary and binary logic operations

More information

MACHINE LEVEL REPRESENTATION OF DATA

MACHINE LEVEL REPRESENTATION OF DATA MACHINE LEVEL REPRESENTATION OF DATA CHAPTER 2 1 Objectives Understand how integers and fractional numbers are represented in binary Explore the relationship between decimal number system and number systems

More information

CS & IT Conversions. Magnitude 10,000 1,

CS & IT Conversions. Magnitude 10,000 1, CS & IT Conversions There are several number systems that you will use when working with computers. These include decimal, binary, octal, and hexadecimal. Knowing how to convert between these number systems

More information

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS (09 periods) Computer Arithmetic: Data Representation, Fixed Point Representation, Floating Point Representation, Addition and

More information

Number representations

Number representations Number representations Number bases Three number bases are of interest: Binary, Octal and Hexadecimal. We look briefly at conversions among them and between each of them and decimal. Binary Base-two, or

More information

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning 4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.

More information

Introduction to Computer Science-103. Midterm

Introduction to Computer Science-103. Midterm Introduction to Computer Science-103 Midterm 1. Convert the following hexadecimal and octal numbers to decimal without using a calculator, showing your work. (6%) a. (ABC.D) 16 2748.8125 b. (411) 8 265

More information

COMP2121: Microprocessors and Interfacing. Number Systems

COMP2121: Microprocessors and Interfacing. Number Systems COMP2121: Microprocessors and Interfacing Number Systems http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 2, 2017 1 1 Overview Positional notation Decimal, hexadecimal, octal and binary Converting

More information

Number Systems CHAPTER Positional Number Systems

Number Systems CHAPTER Positional Number Systems CHAPTER 2 Number Systems Inside computers, information is encoded as patterns of bits because it is easy to construct electronic circuits that exhibit the two alternative states, 0 and 1. The meaning of

More information

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning 4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.

More information

SIGNED AND UNSIGNED SYSTEMS

SIGNED AND UNSIGNED SYSTEMS EE 357 Unit 1 Fixed Point Systems and Arithmetic Learning Objectives Understand the size and systems used by the underlying HW when a variable is declared in a SW program Understand and be able to find

More information

Logic Instructions. Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Segment 4A

Logic Instructions. Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Segment 4A Segment 4A Logic Instructions Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Course Instructor Mohammed Abdul kader Lecturer, EEE, IIUC Basic

More information

COMP Overview of Tutorial #2

COMP Overview of Tutorial #2 COMP 1402 Winter 2008 Tutorial #2 Overview of Tutorial #2 Number representation basics Binary conversions Octal conversions Hexadecimal conversions Signed numbers (signed magnitude, one s and two s complement,

More information

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR UNIT I Digital Systems: Binary Numbers, Octal, Hexa Decimal and other base numbers, Number base conversions, complements, signed binary numbers, Floating point number representation, binary codes, error

More information

CSCI 2212: Intermediate Programming / C Chapter 15

CSCI 2212: Intermediate Programming / C Chapter 15 ... /34 CSCI 222: Intermediate Programming / C Chapter 5 Alice E. Fischer October 9 and 2, 25 ... 2/34 Outline Integer Representations Binary Integers Integer Types Bit Operations Applying Bit Operations

More information

SISTEMI EMBEDDED. Basic Concepts about Computers. Federico Baronti Last version:

SISTEMI EMBEDDED. Basic Concepts about Computers. Federico Baronti Last version: SISTEMI EMBEDDED Basic Concepts about Computers Federico Baronti Last version: 20170307 Embedded System Block Diagram Embedded Computer Embedded System Input Memory Output Sensor Sensor Sensor SENSOR CONDITIONING

More information

CS 101: Computer Programming and Utilization

CS 101: Computer Programming and Utilization CS 101: Computer Programming and Utilization Jul-Nov 2017 Umesh Bellur (cs101@cse.iitb.ac.in) Lecture 3: Number Representa.ons Representing Numbers Digital Circuits can store and manipulate 0 s and 1 s.

More information

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal Positional notation Ch.. /continued Conversions between Decimal and Binary Binary to Decimal - use the definition of a number in a positional number system with base - evaluate the definition formula using

More information

BINARY SYSTEM. Binary system is used in digital systems because it is:

BINARY SYSTEM. Binary system is used in digital systems because it is: CHAPTER 2 CHAPTER CONTENTS 2.1 Binary System 2.2 Binary Arithmetic Operation 2.3 Signed & Unsigned Numbers 2.4 Arithmetic Operations of Signed Numbers 2.5 Hexadecimal Number System 2.6 Octal Number System

More information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 3: Operators, Expressions and Type Conversion 101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

More information

Computer Organization & Systems Exam I Example Questions

Computer Organization & Systems Exam I Example Questions Computer Organization & Systems Exam I Example Questions 1. Pointer Question. Write a function char *circle(char *str) that receives a character pointer (which points to an array that is in standard C

More information

LAB A Translating Data to Binary

LAB A Translating Data to Binary LAB A Translating Data to Binary Create a directory for this lab and perform in it the following groups of tasks: LabA1.java 1. Write the Java app LabA1 that takes an int via a command-line argument args[0]

More information

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,... Chapter 9 Computer Arithmetic Reading: Section 9.1 on pp. 290-296 Computer Representation of Data Groups of two-state devices are used to represent data in a computer. In general, we say the states are

More information

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation Course Schedule CS 221 Computer Architecture Week 3: Information Representation (2) Fall 2001 W1 Sep 11- Sep 14 Introduction W2 Sep 18- Sep 21 Information Representation (1) (Chapter 3) W3 Sep 25- Sep

More information

CS 253. January 14, 2017

CS 253. January 14, 2017 CS 253 Department of Computer Science College of Engineering Boise State University January 14, 2017 1/30 Motivation Most programming tasks can be implemented using abstractions (e.g. representing data

More information

CHAPTER 1 Numerical Representation

CHAPTER 1 Numerical Representation CHAPTER 1 Numerical Representation To process a signal digitally, it must be represented in a digital format. This point may seem obvious, but it turns out that there are a number of different ways to

More information

Computer Organization

Computer Organization Computer Organization Register Transfer Logic Number System Department of Computer Science Missouri University of Science & Technology hurson@mst.edu 1 Decimal Numbers: Base 10 Digits: 0, 1, 2, 3, 4, 5,

More information

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0 Integers So far, we've seen how to convert numbers between bases. How do we represent particular kinds of data in a certain (32-bit) architecture? We will consider integers floating point characters What

More information

Topic Notes: Bits and Bytes and Numbers

Topic Notes: Bits and Bytes and Numbers Computer Science 220 Assembly Language & Comp Architecture Siena College Fall 2010 Topic Notes: Bits and Bytes and Numbers Binary Basics At least some of this will be review, but we will go over it for

More information

N.B. These pastpapers may rely on the knowledge gained from the previous chapters.

N.B. These pastpapers may rely on the knowledge gained from the previous chapters. N.B. These pastpapers may rely on the knowledge gained from the previous chapters. 1 SEC 95-PAPER 1-Q5 (a) A computer uses 8-bit two s complement numbers. In the space below fill in the largest positive

More information

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University. Data Representation ti and Arithmetic for Computers Rui Wang, Assistant professor Dept. of Information and Communication Tongji University it Email: ruiwang@tongji.edu.cn Questions What do you know about

More information

Mid-term Examination

Mid-term Examination Name Student ID Department/Year Mid-term Examination Introduction to Computer Science Class#: 901 E10110, Session#: 03 Spring 2010 15:30-17:10 Wednesday April 21, 2010 Prohibited 1. You are not allowed

More information

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997 Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997 APPENDIX A.1 Number systems and codes Since ten-fingered humans are addicted to the decimal system, and since computers

More information

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS Addition of Unsigned Numbers The instruction ADD is used to add two operands Destination operand is always in register A Source operand can be a register,

More information

Binary Logic (review)

Binary Logic (review) Binary Logic (review) Basic logical operators: (Chapter 7 expanded) NOT AND outputs 1 only if both inputs are 1 OR outputs 1 if at lest one input is 1 XOR outputs 1 if exactly one input is 1 a not 0 1

More information

Chapter 4: Computer Codes. In this chapter you will learn about:

Chapter 4: Computer Codes. In this chapter you will learn about: Ref. Page Slide 1/30 Learning Objectives In this chapter you will learn about: Computer data Computer codes: representation of data in binary Most commonly used computer codes Collating sequence Ref. Page

More information

Topic Notes: Bits and Bytes and Numbers

Topic Notes: Bits and Bytes and Numbers Computer Science 220 Assembly Language & Comp Architecture Siena College Fall 2011 Topic Notes: Bits and Bytes and Numbers Binary Basics At least some of this will be review for most of you, but we start

More information

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer. Digital Logic 1 Data Representations 1.1 The Binary System The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer. The system we

More information

Data Representation and Binary Arithmetic. Lecture 2

Data Representation and Binary Arithmetic. Lecture 2 Data Representation and Binary Arithmetic Lecture 2 Computer Data Data is stored as binary; 0 s and 1 s Because two-state ( 0 & 1 ) logic elements can be manufactured easily Bit: binary digit (smallest

More information

Review of Data Representation & Binary Operations Dhananjai M. Rao CSA Department Miami University

Review of Data Representation & Binary Operations Dhananjai M. Rao CSA Department Miami University Review of Data Representation & Binary Operations Dhananjai M. Rao () CSA Department Miami University 1. Introduction In digital computers all data including numbers, characters, and strings are ultimately

More information

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC 1 2 Semester Transition Point EE 109 Unit 11 Binary Arithmetic At this point we are going to start to transition in our class to look more at the hardware organization and the low-level software that is

More information

Register Transfer and Micro-operations

Register Transfer and Micro-operations Register Transfer Language Register Transfer Bus Memory Transfer Micro-operations Some Application of Logic Micro Operations Register Transfer and Micro-operations Learning Objectives After reading this

More information

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers Computer Science 324 Computer Architecture Mount Holyoke College Fall 2007 Topic Notes: Bits and Bytes and Numbers Number Systems Much of this is review, given the 221 prerequisite Question: how high can

More information

Chapter 2: Number Systems

Chapter 2: Number Systems Chapter 2: Number Systems Logic circuits are used to generate and transmit 1s and 0s to compute and convey information. This two-valued number system is called binary. As presented earlier, there are many

More information

Expression and Operator

Expression and Operator Expression and Operator Examples: Two types: Expressions and Operators 3 + 5; x; x=0; x=x+1; printf("%d",x); Function calls The expressions formed by data and operators An expression in C usually has a

More information

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

More information

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM COURSE / CODE DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) NUMBER SYSTEM A considerable subset of digital systems deals with arithmetic operations. To understand the

More information

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC CHAPTER V-1 CHAPTER V CHAPTER V NUMBER SYSTEMS AND ARITHMETIC CHAPTER V-2 NUMBER SYSTEMS RADIX-R REPRESENTATION Decimal number expansion 73625 10 = ( 7 10 4 ) + ( 3 10 3 ) + ( 6 10 2 ) + ( 2 10 1 ) +(

More information

CO212 Lecture 10: Arithmetic & Logical Unit

CO212 Lecture 10: Arithmetic & Logical Unit CO212 Lecture 10: Arithmetic & Logical Unit Shobhanjana Kalita, Dept. of CSE, Tezpur University Slides courtesy: Computer Architecture and Organization, 9 th Ed, W. Stallings Integer Representation For

More information

Chapter 10 Error Detection and Correction 10.1

Chapter 10 Error Detection and Correction 10.1 Chapter 10 Error Detection and Correction 10.1 10-1 INTRODUCTION some issues related, directly or indirectly, to error detection and correction. Topics discussed in this section: Types of Errors Redundancy

More information

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM 1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM 1.1 Introduction Given that digital logic and memory devices are based on two electrical states (on and off), it is natural to use a number

More information

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

More information

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal Basic Definition REPRESENTING INTEGER DATA Englander Ch. 4 An integer is a number which has no fractional part. Examples: -2022-213 0 1 514 323434565232 Unsigned and -Coded Decimal BCD: -Coded Decimal

More information

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Ziad Matni Dept. of Computer Science, UCSB Adding this Class The class is full I will not be adding more ppl L Even if others

More information

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand Digital Arithmetic Digital Arithmetic: Operations and Circuits Dr. Farahmand Binary Arithmetic Digital circuits are frequently used for arithmetic operations Fundamental arithmetic operations on binary

More information

Bits, Words, and Integers

Bits, Words, and Integers Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are

More information

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010 Contents Number systems and conversion Binary arithmetic Representation of negative numbers Addition of two s complement numbers Addition of one s complement numbers Binary s Readings Unit.~. UNIT NUMBER

More information

UNIT 7A Data Representation: Numbers and Text. Digital Data

UNIT 7A Data Representation: Numbers and Text. Digital Data UNIT 7A Data Representation: Numbers and Text 1 Digital Data 10010101011110101010110101001110 What does this binary sequence represent? It could be: an integer a floating point number text encoded with

More information

DIGITAL SYSTEM DESIGN

DIGITAL SYSTEM DESIGN DIGITAL SYSTEM DESIGN UNIT I: Introduction to Number Systems and Boolean Algebra Digital and Analog Basic Concepts, Some history of Digital Systems-Introduction to number systems, Binary numbers, Number

More information

Number System (Different Ways To Say How Many) Fall 2016

Number System (Different Ways To Say How Many) Fall 2016 Number System (Different Ways To Say How Many) Fall 2016 Introduction to Information and Communication Technologies CSD 102 Email: mehwish.fatima@ciitlahore.edu.pk Website: https://sites.google.com/a/ciitlahore.edu.pk/ict/

More information

Memory Addressing, Binary, and Hexadecimal Review

Memory Addressing, Binary, and Hexadecimal Review C++ By A EXAMPLE Memory Addressing, Binary, and Hexadecimal Review You do not have to understand the concepts in this appendix to become well-versed in C++. You can master C++, however, only if you spend

More information

Chapter 1 Review of Number Systems

Chapter 1 Review of Number Systems 1.1 Introduction Chapter 1 Review of Number Systems Before the inception of digital computers, the only number system that was in common use is the decimal number system which has a total of 10 digits

More information

Lecture (02) Operations on numbering systems

Lecture (02) Operations on numbering systems Lecture (02) Operations on numbering systems By: Dr. Ahmed ElShafee ١ Dr. Ahmed ElShafee, ACU : Spring 2018, CSE202 Logic Design I Complements of a number Complements are used in digital computers to simplify

More information

Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators. Portability: Printing Numbers Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

More information

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as: N Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as: a n a a a The value of this number is given by: = a n Ka a a a a a

More information

Numbers and Representations

Numbers and Representations Çetin Kaya Koç http://koclab.cs.ucsb.edu/teaching/cs192 koc@cs.ucsb.edu Çetin Kaya Koç http://koclab.cs.ucsb.edu Fall 2016 1 / 38 Outline Computational Thinking Representations of integers Binary and decimal

More information

Chapter 2 Number System

Chapter 2 Number System Chapter 2 Number System Embedded Systems with ARM Cortext-M Updated: Tuesday, January 16, 2018 What you should know.. Before coming to this class Decimal Binary Octal Hex 0 0000 00 0x0 1 0001 01 0x1 2

More information

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

CS107, Lecture 3 Bits and Bytes; Bitwise Operators CS107, Lecture 3 Bits and Bytes; Bitwise Operators reading: Bryant & O Hallaron, Ch. 2.1 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative Commons Attribution

More information

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS Aleksandar Milenković The LaCASA Laboratory, ECE Department, The University of Alabama in Huntsville Email: milenka@uah.edu Web:

More information

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS Aleksandar Milenković The LaCASA Laboratory, ECE Department, The University of Alabama in Huntsville Email: milenka@uah.edu Web:

More information

CMPE223/CMSE222 Digital Logic Design. Positional representation

CMPE223/CMSE222 Digital Logic Design. Positional representation CMPE223/CMSE222 Digital Logic Design Number Representation and Arithmetic Circuits: Number Representation and Unsigned Addition Positional representation First consider integers Begin with positive only

More information

Internet Fundamentals

Internet Fundamentals Internet Fundamentals Lecture-10 IPv4 19.2 19-1 IPv4 ADDRESSES An IPv4 address is a 32-bit address that uniquely and universally defines the connection of a device (for example, a computer or a router)

More information

Unsigned Binary Integers

Unsigned Binary Integers Unsigned Binary Integers Given an n-bit number x x n 1 n 2 1 0 n 12 xn 22 x12 x02 Range: 0 to +2 n 1 Example 2.4 Signed and Unsigned Numbers 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0

More information

Unsigned Binary Integers

Unsigned Binary Integers Unsigned Binary Integers Given an n-bit number x x n 1 n 2 1 0 n 12 xn 22 x12 x02 Range: 0 to +2 n 1 Example 2.4 Signed and Unsigned Numbers 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0

More information

Level ISA3: Information Representation

Level ISA3: Information Representation Level ISA3: Information Representation 1 Information as electrical current At the lowest level, each storage unit in a computer s memory is equipped to contain either a high or low voltage signal Each

More information

Inf2C - Computer Systems Lecture 2 Data Representation

Inf2C - Computer Systems Lecture 2 Data Representation Inf2C - Computer Systems Lecture 2 Data Representation Boris Grot School of Informatics University of Edinburgh Last lecture Moore s law Types of computer systems Computer components Computer system stack

More information

The x86 Microprocessors. Introduction. The 80x86 Microprocessors. 1.1 Assembly Language

The x86 Microprocessors. Introduction. The 80x86 Microprocessors. 1.1 Assembly Language The x86 Microprocessors Introduction 1.1 Assembly Language Numbering and Coding Systems Human beings use the decimal system (base 10) Decimal digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Computer systems use the

More information

UNIT 3 OPERATORS. [Marks- 12]

UNIT 3 OPERATORS. [Marks- 12] 1 UNIT 3 OPERATORS [Marks- 12] SYLLABUS 2 INTRODUCTION C supports a rich set of operators such as +, -, *,,

More information

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar Data Representation COE 30 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals Presentation Outline Positional Number

More information

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Fall 2018

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Fall 2018 Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Fall 2018 Ziad Matni, Ph.D. Dept. of Computer Science, UCSB Administrative Stuff The class is full I will not be adding more ppl

More information

Engineering Computing I

Engineering Computing I Engineering Computing I Types, Operators, and Expressions Types Operators Expressions 2 1 2.1 Variable Names Names are made up of letters and digits The first character must be a letter The underscore

More information

Final Labs and Tutors

Final Labs and Tutors ICT106 Fundamentals of Computer Systems - Topic 2 REPRESENTATION AND STORAGE OF INFORMATION Reading: Linux Assembly Programming Language, Ch 2.4-2.9 and 3.6-3.8 Final Labs and Tutors Venue and time South

More information

Signed Binary Numbers

Signed Binary Numbers Signed Binary Numbers Unsigned Binary Numbers We write numbers with as many digits as we need: 0, 99, 65536, 15000, 1979, However, memory locations and CPU registers always hold a constant, fixed number

More information

ENE 334 Microprocessors

ENE 334 Microprocessors Page 1 ENE 334 Microprocessors Lecture 10: MCS-51: Logical and Arithmetic : Dejwoot KHAWPARISUTH http://webstaff.kmutt.ac.th/~dejwoot.kha/ ENE 334 MCS-51 Logical & Arithmetic Page 2 Logical: Objectives

More information

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 CS 64 Lecture 2 Data Representation Reading: FLD 1.2-1.4 Decimal Numbers: Base 10 Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Example: 3271 = (3x10 3 ) + (2x10 2 ) + (7x10 1 ) + (1x10 0 ) 1010 10?= 1010 2?= 1

More information

CHW 261: Logic Design

CHW 261: Logic Design CHW 261: Logic Design Instructors: Prof. Hala Zayed Dr. Ahmed Shalaby http://www.bu.edu.eg/staff/halazayed14 http://bu.edu.eg/staff/ahmedshalaby14# Slide 1 Slide 2 Slide 3 Digital Fundamentals CHAPTER

More information

Numbering systems. Dr Abu Arqoub

Numbering systems. Dr Abu Arqoub Numbering systems The decimal numbering system is widely used, because the people Accustomed (معتاد) to use the hand fingers in their counting. But with the development of the computer science another

More information

CS/EE1012 INTRODUCTION TO COMPUTER ENGINEERING SPRING 2013 HOMEWORK I. Solve all homework and exam problems as shown in class and sample solutions

CS/EE1012 INTRODUCTION TO COMPUTER ENGINEERING SPRING 2013 HOMEWORK I. Solve all homework and exam problems as shown in class and sample solutions CS/EE2 INTRODUCTION TO COMPUTER ENGINEERING SPRING 23 DUE : February 22, 23 HOMEWORK I READ : Related portions of the following chapters : È Chapter È Chapter 2 È Appendix E ASSIGNMENT : There are eight

More information

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column 1's column 10's column 100's column 1000's column 1's column 2's column 4's column 8's column Number Systems Decimal numbers 5374 10 = Binary numbers 1101 2 = Chapter 1 1's column 10's column 100's

More information

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers Outline of Introduction Administrivia What is computer architecture? What do computers do? Representing high level things in binary Data objects: integers, decimals, characters, etc. Memory locations (We

More information

Get Free notes at Module-I One s Complement: Complement all the bits.i.e. makes all 1s as 0s and all 0s as 1s Two s Complement: One s complement+1 SIGNED BINARY NUMBERS Positive integers (including zero)

More information

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers 198:211 Computer Architecture Topics: Lecture 8 (W5) Fall 2012 Data representation 2.1 and 2.2 of the book Floating point 2.4 of the book Computer Architecture What do computers do? Manipulate stored information

More information

Variables and Values

Variables and Values Variables and Values Names Variables (which hold values) and functions (which are blocks of code) both have names Names must begin with a letter and may contain letters, digits, and underscores Names are

More information

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring: ECE 120 Midterm 1 HKN Review Session Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location: Your Room on Compass What to bring: icard, pens/pencils, Cheat sheet (Handwritten) Overview of Review Binary IEEE

More information

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation Complement Number Systems A complement number system is used to represent positive and negative integers A complement number system is based on a fixed length representation of numbers Pretend that integers

More information

Internal Data Representation

Internal Data Representation Appendices This part consists of seven appendices, which provide a wealth of reference material. Appendix A primarily discusses the number systems and their internal representation. Appendix B gives information

More information

CPE300: Digital System Architecture and Design

CPE300: Digital System Architecture and Design CPE300: Digital System Architecture and Design Fall 2011 MW 17:30-18:45 CBC C316 Arithmetic Unit 10122011 http://www.egr.unlv.edu/~b1morris/cpe300/ 2 Outline Recap Fixed Point Arithmetic Addition/Subtraction

More information

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting) 2.1 Unit 2 Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting) 2.2 Skills & Outcomes You should know and be able to apply the following skills with confidence Perform addition & subtraction

More information