Say we intend to store whole numbers and we know that we represent a number using a series of bits (20 is actually, 10100), with 0 < 1. And if we have at the maximum of 16 bits available to us, we can store 1111111111111111 as the maximum value, which comes to 65535. (Note: this conversion is left as an exercise.) But what if we need to store integers? We will need to store within the data the information stating if a number is positive or negative. Standards decide to store the leftmost bit as a sign, 0 for + and 1 for -. So, if we have at the maximum of 16 bits, one bit will be reserved for sign and the remaining 15 will be used for value. Thus, we could have at the maximum value of 0 111111111111111, i.e. +32767. What should be least possible value? Guess!
Let’s go back to history of mathematics again. We decide to cut an apple into two pieces (division). After cutting that apple, what should each piece represent? One apple? We called it ½ or 0.5 part of an apple. Thus real numbers (float) we born, of the format sign-number-dot-number.
How should be represent real numbers? Standards choose scientific method to represent numbers, e.g., 256.6 is represented as 2.566 x 10^2 (10 to the power 2). How should we represent it in binary format? We could do it using three divisions of our string of bits (that will represent the number), one bit for + or -, some bits to be reserved to represent 2566, and some to represent 2 (the power). In addition we could consider that the system always has a decimal after first number and that the power is always to 10. But, there is a limitation of this system, we can’t represent some values. So, they may be represented as next-higher or previous-lower value (a value that could be represented). Thus, floating point numbers should be considered to be approximate. Typically, real numbers are given more bits than are allocated for integers for representation.
Subscribe to:
Post Comments (Atom)
0 Response to "Working with Bits"
Post a Comment