bplus: Point well made... Counterpoint. Will BIN$() teach the user 'how' it is converted? Nothing wrong with using the command but knowing how it is done is beneficial if one is using a 'basic' that does not utilize the BIN$() function...
@bplus
please Screenshot!
Something tells me this work would all be a lot easier if you guys used the BIT routines; _SETBIT and _READBIT.
Just saying.
Yeah? so show us 27/101 in Binary :)
you do realize that binary only deals in 1 and 0 right. 27/101 is not a 1 or a 0
For 27/101, and if I set the value of the MSbit to 1, I get:
0010 0010 0011 0111 1100 0011 0010 1011 0001 0110 1100 1111 11011
which are then followed by binary zeroes. Which implies to me that I've reached the limit of the accuracy of _Float.
This is where I compute the binary numbers, bit by bit. Also, my super duper program also gives the hex equivalent.
hex 2237C32B16CFD800
neither is 5.
You do realize that binary means base 2? Any number expressed in one base can be expressed in another by conversion.
what I am saying is Binary can only express whole numbers. there are no fractions or decimals in binary.
what I am saying is Binary can only express whole numbers. there are no fractions or decimals in binary.
1001.1001
You can represent any decimal fractional number in Binary, as any systems programmer will tell you.
It is just not that simple.
Rather than me botching up or giving a convoluted explanation, here are some excellent sources:
https://stackoverflow.com/questions/4987176/how-do-you-convert-a-fraction-to-binary (https://stackoverflow.com/questions/4987176/how-do-you-convert-a-fraction-to-binary)
https://www.electronics-tutorials.ws/binary/binary-fractions.html (https://www.electronics-tutorials.ws/binary/binary-fractions.html)
https://isaaccomputerscience.org/concepts/data_numbases_fractional_numbers (https://isaaccomputerscience.org/concepts/data_numbases_fractional_numbers)
show me how to store this
Quote from: SMcNeill on Today at 12:37:15 PM
1001.1001
But then again who would want to deal with it? Just show me one real-world example where you need that level of precision, not theoretical but real-world. Do I need to worry about the mass of quarks or boson particles in my day to day activities? Probably not.
I think we are just on 2 different planes here,
show me how to store this
in a BYTE, INTEGER, LONG, SINGLE, DOUBLE, or FLOAT?
In the computer store that binary sequence. with out extra code, just simple BINARYBLAH = 1001.1001
I'm not saying on paper or on the screen as text, but inside the memory. That's all.
Yeah you can express or represent a decimal or fraction with binary values, but not store it. that information is not stored, its decoded. I was talking how that is stored. I think that is where we diverged. A simple miscommunication? I was talking oranges while you were talking apples? Both fruit but not the same.
Imagine the precision if you used an INTEGER64 to hold the decimal side! or multiple INT64s!
1\18446744073709551616
But then again who would want to deal with it? Just show me one real-world example where you need that level of precision, not theoretical but real-world. Do I need to worry about the mass of quarks or boson particles in my day to day activities? Probably not.
b$ = "1001.1001"
Say you work in a machine shop and all the washers are sized 1/2 inch, 1/4 inch, 1/8 inch, 1/16 inch ... (widths or thickness not radius or hole size)
and you have a .1001 base 2 inch space to fill (9/16 inches)
easy that takes 1 - 1/2 inch washer + 1 - 1/16 inch washer
easy because it's base 2 math like the washer sizes!
FYI, that's not a _BYTE, INTEGER, LONG, SINGLE, DOUBLE or FLOAT.
I meant to the precision of an Integer64. if it was used as the decimal precision.
You asked, "show me how to store this".
I think we are just on 2 different planes here,
show me how to store this
in a BYTE, INTEGER, LONG, SINGLE, DOUBLE, or FLOAT?
And, to show that these values are true and represented in memory in this manner, we have the following little program:
IEEE Short Real: 32 bits 1 bit for the sign, 8 bits for the exponent, and 23 bits for the mantissa. Also called single precision.so using SINGLE PRECISION (!)
+1101.101 0 10000010 10110100000000000000000
Thanks @Bert22306 we seem to have the same expression except you don't show a decimal. Since 27/101 is .2673 with bar over top to represent repeating 4 digits, I think .01... does it with decimal placement as:
.1 base 2 = 1/2
.01 base 2 = 1/4 or .25
.001 base 2 = 1/8 or .125
...
here if I make the rest of that line big and bold can you read it then?