May 23, 2024, 06:54:45 AM

1,531,628 Posts in 46,728 Topics by 1,523 Members
› View the most recent posts on the forum.


so i took the previous class like 3 years ago

Started by Daddy, January 21, 2012, 08:52:36 PM

previous topic - next topic

0 Members and 1 Guest are viewing this topic.

Go Down

Daddy

I can't remember how to convert a floating point number (e.g. 100.25) to binary ;____; akudood;

bluaki

January 21, 2012, 09:14:25 PM #1 Last Edit: January 22, 2012, 02:55:45 AM by bluaki
Convert both the whole and fractional parts to binary form (1100100.01), convert that to base-2 scientific notation in the form of 1.XXXXX * 2^Y (1.10010001 * 2^6), and for standard data representations, assign the bits to:
first bit 0 for positive
next few bits are that exponent Y represented in biased format: for N bits, shift all numbers up by 2^(N-1) to allow a range between +-2^(N-1)
last set of bits are the XXXXX above (with the preceding 1. removed) and any necessary trailing bits zeroed

the number of bits available in each of the latter parts should be given to you in the problem or can be looked up if they say it's an IEEE standard 32-bit or 64-bit floating-point number

silvertone


Cosmic Ada


Daddy

Quote from: bluaki on January 21, 2012, 09:14:25 PM
Convert both the whole and fractional parts to binary form (1100100.01), convert that to base-2 scientific notation in the form of 1.XXXXX * 2^Y (1.10010001 * 2^6), and for standard data representations, assign the bits to:
first bit 0 for positive
next few bits are that exponent Y represented in biased format: for N bits, shift all numbers up by 2^(N-1) to allow a range between +-2^(N-1)
last set of bits are the XXXXX above (with the preceding 1. removed) and any necessary trailing bits zeroed

the number of bits available in each of the latter parts should be given to you in the problem or can be looked up if they say it's an IEEE standard 32-bit or 64-bit floating-point number
How do you convert a fraction to binary 5thgrade;

bluaki

Quote from: Khadafi on January 22, 2012, 09:18:45 AM
How do you convert a fraction to binary 5thgrade;
In this case, you can simply recognize that 0.25 is 1/4 or 2^-2

Otherwise, you can either:
Find the largest negative exponent of 2 that's smaller than the number you have, subtract that value from your number, and repeat. (easier for simpler numbers like 0.375 which is 0.25+0.125)
Remembering what exponent of 2 you are currently on, repeatedly multiply the number by two, and subtract the number by 1 whenever you can while filling its bit.
Very often the result would be a nonterminating fractional part (like converting 1/3 to base-10) and you just have to stop at some point.

Like for 0.4:
at position 2^0, can't subtract one (0 bit)
0.4*2 = 0.8
at position 2^-1, can't subtract one (0 bit)
0.8*2 = 1.6
at position 2^-2, subtracting one (result will have a 1 at the 2^-2 position)
0.6*2 = 1.2
at position 2^-3, subtracting one (1 bit)
0.2*2 = 0.4
at position 2^-4, can't subtract one (0 bit)
at this point, the current number is one you've previously used, so anything else will repeat those digits

Can't do an overbar in bbcode, but using underline instead to represent a repeating part it's 0.0110

strongbad


Go Up