11-06-04, 09:03 PM
How to convert from base 2 to 10 or 10 to 2????????
Including conversion of integers, decimals
How to carry out mathematical operations in base 2????????????????
11-06-04, 10:22 PM
To convert from base 10 to base 2:
find out how many digits you need by taking log base 2 of your number, which we shall call x, rounded down plus 1.
Take n equal to the number of digits.
Set each digit (starting from the left) by doing integer division of number x, and then set x as the remainder.
decrement n and repeat the previous step until n=0.
eg. 168 has 8 digits, 10101000
To go from 2 to 10:
Multiply each digit by 2 to the power of of its distance from the right minus 1.
Why do you ask?
11-07-04, 04:21 AM
decimals depends upon the format of the number. As I recall the number is normalised in the form of .101110101(there is an implicit 1 at the start that need not be recorded). The exponent is used to tell how far to move the "decimal" point. There is also a sign bit.
The IEEE convention is:
1 bit sign /8 bit exponent/23 bit mantissa:
0 11111111 0101010 10101010 10101010
the exponent(unsigned) is converted to decimal, and then has 127 subtracted from it. if -ve, the dp goes <---. If +ve the dp goes --->.
So the mantissa, 11111111. (or 2<sup>7</sup> after the bias is removed) means the dp goes 7 to the right. That is your floating point.
To convert a binary no to base human:
is merely 2<sup>5</sup> * 1 +
2<sup>3</sup> *1 +
2<sup>2</sup> *0 +
2<sup>1</sup> *1 +
2<sup>0</sup> *0 +
2<sup>-1</sup> *1 +
2<sup>-2</sup> *0 +
does that make any sense at all?
11-07-04, 12:14 PM
Surely the exponent is the power of two to which the number is raised? Your exponent (which you have mis-named the mantissa) is 128 in decimal, which means the dp. moves 128 places right. You're multiplying by the exponent. And isn't the exponent in twos complement form, where the msb is negative, and all the others are positive? That would make your exponent -1.
11-07-04, 11:38 PM
Your exponent (which you have mis-named the mantissa) is 128 in decimal, which means the dp. moves 128 places right.
True. Should read: "(or 2<sup>7</sup> after the bias is removed) means the dp goes 2<sup>7</sup> to the right. ". Which is also wrong(should be 2<sup>7</sup>-1)
And isn't the exponent in twos complement form, where the msb is negative, and all the others are positive?
No, it's biased. The reason is that 2's comp would make comparisons too hard.
The exponent, which is a signed integer in the range from -126 to 127, is represented neither as a signed magnitude nor as a twos-complement number, but as a biased value. The idea here is that the integers in the desired range of exponents are first adjusted by adding a fixed ``bias'' to each one. The bias is chosen to be large enough to convert every integer in the range into a positive integer, which is then stored as a binary numeral. The IEEE single-precision representation uses a bias of 127.
edit: was also incorrect in that the bias is added and not subtracted.