@Keltari Generally, fraction value CAN be represented in binary, using kind of "binary point" (counterpart of decimal point). In fact, that is how real/double numbers are represented in computers (although usually binary point position is stored, instead of the "point character"). But remember: not all decimal fractions can be represented in binary form exactly - some rounding must be applied then, especially if only limited count of bits can be used (which is always true in real computer science world).
Unfortunatelly, windows calculator in programmer's mode operate on integer values only. A workaround to achieve your goal is like this:
In standard mode enter a decimal number (can be fractional) to convert, e.g. 0.21
Multiply it by 2 (keys: * 2 =)
Repeat step 2 (pressing = key alone, again and again), until you receive number which is integer - or very close to integer (see remark below).
IMPORTANT! Remember, how many times you multiplied initial value by 2 (in step 2 and repeated 3).
Switch to programmer's mode and enter value received after step 3, rounded to integer (unfortunately, that is not done automatically when switching mode, at least in Windows 10's Calculator app).
The binary representation of the integer number is shown. Imagine, the binary point is on the most right (after last binary digit). Then, move it left by as many positions as you have done multiplying in step 2 and 3. Add leading 0's as needed.
Example:
- Original value:
0.21
- Multiply it by 2 ten times - you get
215,04
. Assuming that it is close enough to an integer value (it is arbitrary decision!), you get the rounded integer of 215
- Entering
215
in programmer's mode shows its binary representation: 11010111
- Moving the binary point 10 places left, gives:
.0011010111
Remark: As I mentioned earlier, not all decimal fraction values can be represented exactly in binary form, so sometimes you must decide, what precision (approximation) satisfy your needs. In the example above, I assumed that rounding 215,04 to 215 is comparatively small "error" (below 1/5000), so 10 bits was enough to represent the original number. If I needed greater precision, I would make multiplying by 2 not ten, but maybe twenty times (result: 220200,96
rounded to 220201
as an integer) and would get 20-bits binary representation .00110101110000101001
(with "error" below 1/5000000).
BTW Usually count of bits used to represent data in computers is power of 2 - 8, 16, 32, 64, sometimes 48, etc. In such a case, you can simply use faster "multipling by 2" method in the calculator, suggested by you in comment below (*(2^n)
).
This is because you cannot represent fractions in binary. – Keltari – 2017-11-27T21:49:39.490
Not entirely correct. You can, but Windows calculator doesn't show. When we see a number, say
123
, we don't even think this way, but in reality, the number can be broken down into1*10^2 + 2*10^1 + 10^0
, by the same logic,123.45
is1*10^2 + 2*10^1 + 3*10^0 + 4*10^(-1) + 5*10^(-2)
. The exact same thing happens with the binary math, except you only have 2 digits (represented by0
and1
) and the base of the system is2
, not10
. So0.21
could be viewed as0.0011010111
which is approximated as0.209961
, I only did 10 binary digits, IEEE-754 standard specifies a lot more... – nurchi – 2017-11-27T22:55:40.707@nurchi You mean that Keltari is not correct. You're replying to Keltari not to me, so please write AT Keltari at the start of your comment, so it's clear you were referring to him and not to me – barlop – 2017-11-28T03:49:46.697
Seems like I cannot edit my comment anymore, but yes, I was referring to @Keltari's comment, not the question itself. – nurchi – 2017-12-15T20:29:10.300