CYBER3123 - Chapter 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

2.4 Signed Representation

-By convention, a 1 in the high-order bit indicates a negative number. The remaining bits (after the sign bit) are used to represent the number itself. 2.4.1 - Signed Magnitude -The set of positive and negative integers is referred to as the set of signed integers. The problem with representing signed integers as binary values is the sign—how should we encode the actual sign of the number? Signed-magnitude representation is one method of solving this problem. As its name implies, a signed-magnitude number has a sign as its leftmost bit (also referred to as the high-order bit or the most significant bit), whereas the remaining bits represent the magnitude (or absolute value) of the numeric value. In a computer system that uses signed-magnitude representation and 8 bits to store integers, 7 bits can be used for the actual representation of the magnitude of the number. This means that the largest integer an 8-bit word can represent is 27 - 1, or 127 (a 0 in the high-order bit, followed by 7 1s). The smallest integer is 8 1s, or -127. Therefore, N bits can represent −(2^(N−1) − 1) to 2^(N−1)-1. Ex: For 8 bit, 2^(8-1)-1 minuend: top number in subtraction subtrahend: bottom number in subtraction -Ex: Add 010011112 to 001000112 using signed-magnitude arithmetic. 1 1 1 1 <- carries 0 1 0 0 1 1 1 1 (79) 0 + 0 1 0 0 0 1 1 (35) ------------------ 0 1 1 1 0 0 1 0 (114) Sign bits are segregated because they are relevant only after the addition is complete. In this case, we have the sum of two positive numbers, which is positive. Overflow (and thus an erroneous result) in signed numbers occurs when the sign of the result is incorrect. In signed magnitude, the sign bit is used only for the sign, so we can't "carry into" it. If there is a carry emitting from the seventh bit, our result will be truncated as the seventh bit overflows, giving an incorrect sum. -Dabbling the double: The fastest way to convert a binary number to decimal is a method called double-dabble (or double-dibble). This method builds on the idea that a subsequent power of two is double the previous power of two in a binary number. The calculation starts with the leftmost bit and works toward the rightmost bit. The first bit is doubled and added to the next bit. This sum is then doubled and added to the following bit. The process is repeated for each bit until the rightmost bit has been used. -Ex: Convert 10010011(base)2 to decimal. Step 1) Write down the binary number, leaving space between the bits. 1 0 0 1 0 0 1 1 Step 2: Double the high-order bit and copy it under the next bit. 1 0 0 1 0 0 1 1 2 4 8 18 36 72 146 +0 +0 +1 +0 +0 +1 +1 --- --- --- --- --- --- --- 2 4 9 18 36 73 147 <--- Answer: 147(base)10 x2 x2 x2 x2 x2 x2 x2 --- --- --- --- --- --- --- 2 4 8 18 36 72 146 Subtraction using Signed arithmetic: -As with addition, signed-magnitude subtraction is carried out in a manner similar to pencil-and-paper decimal arithmetic, where it is sometimes necessary to borrow from digits in the minuend. -Recall the rules for addition: (1) If the signs are the same, add the magnitudes and use that same sign for the result; (2) If the signs differ, you must determine which operand has the larger magnitude. The sign of the result is the same as the sign of the operand with the larger magnitude, and the magnitude must be obtained by subtracting (not adding) the smaller one from the larger one.

2.2 - Positional Numbering Systems

-During the middle of the sixteenth century, Europe embraced the decimal (or base 10) numbering system that the Arabs and Hindus had been using for nearly a millennium. -The general idea behind positional numbering systems is that a numeric value is represented through increasing powers of a radix (or base). This is often referred to as a weighted numbering system because each position is weighted by a power of the radix. The set of valid numerals for a positional numbering system is equal in size to the radix of that system. To distinguish among numbers in different radices, we use the radix as a subscript, such as in 3310 to represent the decimal number 33. (In this text, numbers written without a subscript should be assumed to be decimal.) Any decimal integer can be expressed exactly in any other integral base system -The two most important radices in computer science are binary (base two) and hexadecimal (base 16). Another radix of interest is octal (base 8). The binary system uses only the digits 0 and 1; the octal system, 0 through 7. The hexadecimal system allows the digits 0 through 9 with A, B, C, D, E, and F being used to represent the numbers 10 through 15.

2.3 - Converting Between Bases

-Gottfried Leibniz (1646−1716) was the first to generalize the idea of the (positional) decimal system to other bases. Being a deeply spiritual person, Leibniz attributed divine qualities to the binary system. He correlated the fact that any integer could be represented by a series of 1s and 0s with the idea that God (1) created the universe out of nothing (0). -Because of its simplicity, the binary numbering system translates easily into electronic circuitry. It is also easy for humans to understand. Converting Unsigned Whole Numbers: We know that 8^3 = 512 is the highest power of 8 that is less than 538, so our base 8 number will be 4 digits wide (one for each power of the radix: 0 through 3). Subtraction: 538 -512 = 8^3 x 1 ---- 26 -0 = 8^2 x 0 ---- 26 -24 = 8^1 x 3 ---- 2 -2 = 8^0 x 2 ---- 0 538(base)10 = 1032(base)8 Division (Faster/Easier): It employs the idea that successive divisions by the base are in fact successive subtractions by powers of the base. The remainders that we get when we sequentially divide by the base end up being the digits of the result, which are read from bottom to top. Ex: =538/8 r:2 8 divides 538, 67 times with a remainder of 2. =67/8 r:3 8 divides 67, 8 times with a remainder of 3. =8/8 r:0 8 divides 8, 1 times with a remainder of 0. =1/8 r:1 8 divides 1, 0 times with a remainder of 1. =0 Reading the remainders from bottom to top, we have: 538(base)10 = 1032(base)8. -This method works with any base, and because of the simplicity of the calculations, it is particularly useful in converting from decimal to binary. Ex: Convert 147(base)10 to binary. (Binary is base 2) =147/2 r:1 2 divides 147, 73 times with a remainder of 1. =73/2 r:1 2 divides 73, 36 times with a remainder of 1. =36/2 r:0 2 divides 36, 18 times with a remainder of 0. =18/2 r:0 2 divides 18, 9 times with a remainder of 0. =9/2 r:1 2 divides 9, 4 times with a remainder of 1. =4/2 r:0 2 divides 4, 2 times with a remainder of 0. =2/2 r:0 2 divides 2, 1 times with a remainder of 0. =1/2 r:1 2 divides 1, 0 times with a remainder of 1. =0 Reading the remainders from bottom to top, we have: 147(base)10 = 10010011(base)2. -A binary number with N bits can represent unsigned integers from 0 to 2^N − 1. For example, 4 bits can represent the decimal values 0 through 15, whereas 8 bits can represent the values 0 through 255. -Consider a situation in which binary numbers are 4 bits in length, and we wish to add 1111(base)2 (15(base)10) to 1111(base)2. We know that 15 plus 15 is 30, but 30 cannot be represented using only 4 bits. This is an example of a condition known as OVERFLOW, which occurs in unsigned binary representation when the result of an arithmetic operation is outside the range of allowable precision for the given number of bits. Converting Fractions: -Fractions in any base system can be approximated in any other base system using negative powers of a radix. Radix points separate the integer part of a number from its fractional part. In the decimal system, the radix point is called a decimal point. Binary fractions have a binary point. We can convert fractions between different bases using methods analogous to the repeated subtraction and division-remainder methods for converting integers Ex: Convert 0.4304(base)10 to base 5. 0.4304 - 0.4000 = 5^(-1) * 2 --------- = 0.0304 -0.0000 = 5^(-2) * 0 --------- = 0.0304 -0.0240 = 5^(-3) * 3 --------- = 0.0064 -0.0064 = 5^(-4) * 4 --------- = 0.0000 Reading from top to bottom, we have: 0.4304(base)10 = 0.2034(base)5. Because the remainder method works with positive powers of the radix for conversion of integers, it stands to reason that we would use multiplication to convert fractions, because they are expressed in negative powers of the radix. However, instead of looking for remainders, as we did above, we use only the integer part of the product after multiplication by the radix. The answer is read from top to bottom instead of bottom to top. 0.4304 x 5 --------- 2.1520 The integer part is 2. Omit integer next multiply .1520 x 5 --------- 0.7600 The integer part is 0. Use as placeholder .7600 x 5 --------- 3.8000 The integer part is 3. Omit integer next multiply .8000 x 5 --------- 4.0000 The fractional part is now 0, so we are done. -Ex: Exception Convert 3121(base)4 to base 3. 1) First, convert to decimal (base 10) 2) Then convert to base 3 2.3.3 Converting Between Power-of-Two Radices -Binary numbers are often expressed in hexadecimal—and sometimes octal—to improve their readability. Because 16 = 24, a group of 4 bits (called a hextet) is easily recognized as a hexadecimal digit. Similarly, with 8 = 23, a group of 3 bits (called an octet) is expressible as one octal digit. Using these relationships, we can therefore convert a number from binary to octal or hexadecimal by doing little more than looking at it. -Convert 110010011101(base)2 to octal and hexadecimal. Octal Conversion: Separate into groups of 3 bits for the octal conversion Ex: 110 010 011 101 --- --- --- --- 6 2 3 5 so, 110010011101(base)2 = 6235(base)8 Hexadecimal Conversion: Separate into groups of 4 bits for the hexadecimal conversion Ex: 1100 1001 1101 ---- ---- ---- 6 2 3 so, 110010011101(base)2 = C9D(base)16 ***If there are too few bits, leading 0s can be added.

Section 2.1

-The organization of any computer depends considerably on how it represents numbers, characters, and control information. The converse is also true: Standards and conventions established over the years have determined certain aspects of computer organization. -The most basic unit of information in a digital computer is called a bit, which is a contraction of binary digit. In the concrete sense, a bit is nothing more than a state of "on" or "off " (or "high" and "low") within a computer circuit. -Computer words consist of two or more adjacent bytes that are sometimes addressed and almost always are manipulated collectively. The word size represents the data size that is handled most efficiently by a particular architecture. Words can be 16 bits, 32 bits, 64 bits, or any other size that makes sense in the context of a computer's organization (including sizes that are not multiples of eight) -8-bit byte can be divided into two 4-bit halves called nibbles (or nybbles). Because each bit of a byte has a value within a positional numbering system, the nibble containing the least-valued binary digit is called the low-order nibble, and the other half the high-order nibble.


Set pelajaran terkait

Chapters 1 & 2 MIT 217: Medical Office Procedures

View Set

NCE2 L80 The Crystal Palace 水晶宫

View Set

Honors World History Slear-Final Exam prep

View Set

Family and Consumer Science Composite

View Set

EA 150 Chapter 4 Review Questions

View Set