Hey Professor Bitrake, Let's correct my first test......

+0 could be

+ 127 0
1 01111111 000000000000000000000000

Wrong: leading one bit is implied - this is actually -1.0. Also, by setting the top bit the number becomes negitive - this is wrong on all conversions.
--------------------------------------
+0.232 could be

+ 127-1 232
1 01111110 111010000000000000000000

Wrong: the number above is -1.11101 x 2^-1 {binary} = -61/64 {decimal}
--------------------------------------

The numbers need to be convered to binary and then the decimal place is shifted.

Example:

+ 7854.23 {decimal} = 1111010101110.00111010111 {binary}

* Now we move the decimal place to the left - this adds to the 127 bias.

+ 127+12 7696855

0 10001011 11101010111000111010111

* Notice the leading zero - this means positive.
* 127+12 = 139 = 10001011 {binary}
* After shifting until only one bit remained to the left of the decimal, that one bit is removed and only the right side 23 bits are stored in the REAL4 float.
Posted on 2003-06-21 10:57:52 by bitRAKE
I dont get it

7854.23 {decimal} = 1111010101110.00111010111 {binary} ???

1111010101110 (bin) ok thats 7854 (dec)
but
00111010111 (bin) != 23 (dec)

10111 == 23

but than what about 001110 == 14

and the question is what should i do with 7854 23 and 14 to obtain 7854.23 ??????????

bitRake can you explain step by step how to convert it, like talking to 5 years old ??

BTW. Angelo it looks like you have failed :tongue:
Posted on 2003-06-21 11:54:41 by AceEmbler
ok, professor, here we go, now i should be a bit more preapred.

``````

+234.5678
become
+11101010.1011000101110
floating will be
0 10000110 11010101011000101110000
436AB170h

--------------------------------------

-1.2311
become
-1.100100000111
floating will be
1 01111111 10010000011100000000000

---------------------------------------

my trouble remain  +0.0
become
+0.0
float could be
0 00000000 00000000000000000000000

B7

``````
Posted on 2003-06-21 13:48:28 by Bit7
CONCLUSION of the study:

To generate a floating random number between 0.0 and 1.0

i should have a fix part as

0 01111110

plus the fraction as XXXXXXXXXXXXXXXXXXXXXXX

the 23 x's ca nbe changed by a seed that shift. Obviousli values +0.0 and +1.0 are excluded.

B7
Posted on 2003-06-21 14:22:30 by Bit7
k now it's my turn :tongue:

456.567 (dec)

456 (dec) = 111001000
567 (dec) = 1000110111

456.567 (dec) == 111001000.1000110111

[+][127+8]1110010001000110111

0 10000111 11100100010001101110000

This one will be more difficult : :grin:

-0.6709 (dec)

6709 (dec) == 1101000110101 (bin)
0 (dec)== 0 bin :tongue:

-0.1101000110101

[-][127-1]1101000110101

1 01111110 11010001101010000000000
Posted on 2003-06-21 14:30:08 by AceEmbler

CONCLUSION of the study:

To generate a floating random number between 0.0 and 1.0

i should have a fix part as

0 01111110

plus the fraction as XXXXXXXXXXXXXXXXXXXXXXX

the 23 x's ca nbe changed by a seed that shift. Obviousli values +0.0 and +1.0 are excluded.

B7
Very good idea. Another would be to subtract 1.0 from random number - overcoming the implied one bit - this allows zero as outcome.
Posted on 2003-06-23 11:25:23 by bitRAKE
AceEmbler, fractions are not converted by just converting the number.

I do it like this:

n = bits of percision needed
X = fraction

INT(2^n * X)

Remember that all (n) bits must be used - cannot remove leading zeroes, but can remove trailing zeros and have the same number - like base 10 numbers.

Examples:

0.5 = 0.1 {binary}
0.5 = 0.100 {binary}
0.5 = 0.1000_0 {binary}

0.75 = 0.11 {binary}
0.75 = 0.110 {binary}

0.0123 = 0.01100 10011 00001 01111 10000 011 {binary}
(The above conversion isn't exact, but is pretty good.)

0.001 = 0.00000 00001 00000 11000 10010 01101 1101 {binary}

Think about what each place means for decimal and then for binary:

Decimal:
0.1 means 1/10
0.01 means 1/100

Binary:
0.1 means 1/2
0.01 means 1/4
0.001 means 1/8
Posted on 2003-06-23 11:52:52 by bitRAKE
thanks BitRake, now i know a thing more :]
Posted on 2003-06-23 14:30:22 by Bit7
mov ecx, 418937h
mul ecx
; EDX is similar to SomeNumber divided by 1000 ;)
Posted on 2003-06-23 18:58:16 by bitRAKE
One detail which is important to understand the floating point format is that it is a binary scientific format somewhat similar to the scientific format for the decimal numbers. For example, in the decimal base,
``````
12345 =     [b]1.2345[/b]e+04
123.45 =    [b]1.2345[/b]e+02
0.0012345 = [b]1.2345[/b]e-03``````

The description of the number has not changed, only the exponent of 10.

In floating point format, you look at multiples of 2 (instead of 10). So, a value of 5 could be written as:
``101b = 1.01b x 2^2``

Then, if you divide 5 by 8 (2^3), you would get:
``1.01 x 2^(-1)``

This means that, in binary scientific (floating point) format, the only difference between 5 and 5/8 (0.625) will be in the exponent field.
``````
Decimal     REAL4                               (hex)
5        0 10000001 01000000000000000000000  (40A00000)
0.625      0 01111110 01000000000000000000000  (3F200000)``````

You could continue to divide by 2 without changing the 23-bit field for the number description until you reach the lower limit of the REAL4 format.

Raymond
Posted on 2003-06-24 09:31:39 by Raymond
Still dont get it.

0.0123 = 0.01100 10011 00001 01111 10000 011 {binary}
(The above conversion isn't exact, but is pretty good.)

how 123 can be that long???
Posted on 2003-06-24 15:16:47 by AceEmbler

how 123 can be that long???
How can pi be that long? ...or e? 0.0123 does not equal an exact sum of powers of 2 - there is no direct translation.
Posted on 2003-06-24 16:16:39 by bitRAKE