Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

How would you write a fraction in binary numbers; for example, $1/4$, which is $.25$? I know how to write binary of whole numbers such as 6, being $110$, but how would one write fractions?

share|improve this question
9  
The same way. $\frac{n}{m}$. So a quarter would be $\frac{1}{100}$. –  copper.hat Feb 12 '13 at 18:47
    
You might want to have a look at: cs.furman.edu/digitaldomain/more/ch6/dec_frac_to_bin.htm. You can then use WA to test examples. Regards –  Amzoti Feb 12 '13 at 18:49
    
I think this is a duplicate. Will have a look. –  Tara B Feb 12 '13 at 18:52
    
If it is it made by another person –  Fernando Martinez Feb 12 '13 at 18:54
1  
Si me gustan todos esto thumbs up.... –  Fernando Martinez Feb 15 '13 at 18:41

8 Answers 8

up vote 21 down vote accepted

Note: $$\dfrac 14_{\,\text{ ten}} = .25 = \color{blue}{\bf 2} \times 10^{-1} + \color{blue}{\bf 5} \times 10^{-2} $$ $$ \frac14= \dfrac{1}{2^2}_{\,\text{ten}} = 2^{-2} = \color{blue}{\bf 0} \times 2^{-1} + \color{blue}{\bf 1}\cdot 2^{-2} = .01_{\text{ two}}$$

share|improve this answer
    
Yes I like this answer the most. –  Fernando Martinez Feb 12 '13 at 18:58
    
So I I had $\frac{1}{8}$ would I do $(2^{-3}+2^{-2}+2^{-1}+2^0)$ –  Fernando Martinez Feb 12 '13 at 19:00
3  
Yup, but start with $\frac 18 = 2^{-3} = 0 \times 2^{-1} + 0\times 2^{-2} + 1\times 2^{-3} = 0.001_{\text{two}}$ –  amWhy Feb 12 '13 at 19:02
    
yes that makes sense. –  Fernando Martinez Feb 12 '13 at 19:04
1  
$2^0 \iff \;$ the "one's place". $2^{-1}$ corresponds to the first digit to the right of the decimal point, then the place to the right of that corresponds to $2^{-2}$...and so on. –  amWhy Feb 12 '13 at 19:05

As you mentioned, $$6 = {\color{red}1}\cdot 2^2+ {\color{red}1}\cdot 2^1+{\color{red}0}\cdot 2^0 = {\color{red}{110}}_B.$$ Analogously $$\frac{1}{4} = \frac{1}{2^2} = {\color{red}0}\cdot2^0 + {\color{red}0}\cdot 2^{-1} + {\color{red}1}\cdot 2^{-2} = {\color{red}{0.01}}_B.$$

Edit:

These pictures might give you some more intuition ;-) Here $\frac{5}{16} = 0.0101_B$, as the denominator is of form $2^n$, the representation is finite (process ends when you hit zero); $\frac{1}{6} = 0.0010\overline{10}_B$ as the denominator is not of form $2^n$, but the number is rational, so representation is infinite and periodic.

binary fraction 5/15 binary fraction 1/6

I hope this helps ;-)

share|improve this answer

$1/4=0\cdot(1/2)^0+0\cdot(1/2)^1+1\cdot(1/2)^2=0.01$ in base $2$, you just go in reverse with powers $(1/2)^n, n=0,1,2,...$

share|improve this answer

Three basic ways, all seen in binary number systems:

Fixed-Point: One integer holds the "integer part"; another holds the "fractional part". This is simple to store and display, and has very high magnitude and precision with virtually no error, but doing real math with the numbers involved can get hairy. Decimal numbers aren't often seen in this form, but it is a possibility.

Maintained Floating Point: a large integer holds the entire value, and a second smaller number maintains the relative place of the decimal point from the right (or left) side of the number. Much easier to manipulate for mathematical operations, same maintenance of precision, zero error, and used in many implementations of "BigDecimal" object types where the "built-in" floating point mechanisms aren't available. Can be more difficult to represent in base-10 form on-screen. If implemented with normal integer types, this method can be more limited in magnitude than the previous one; instead, many implementations use a byte array to store the number, allowing the numbers to be as big as system memory allows.

Implicit Floating Point: The number is expressed in what amounts to "binary scientific notation". A "mantissa" is stored as an integer, with the decimal point implied to be on the far right. Then the exponent of a power of two is also stored. The actual value of this number is the mantissa, multiplied by two to the power of the exponent. This approach allows for the storage and calculation of truly massive numbers, and modern CPUs are designed with a Floating-Point Unit or FPU (sometimes called a "math co-processor", in the early days of its integration into 486-class CPUs) that accelerates calculations of numbers in this form. However, there are two problems; first, there's a tradeoff between extreme precision and extreme magnitude; the mantissa, and thus the number of digits that can be stored precisely, is fixed, so as magnitude increases, the number of possible decimal places decreases (in the extremes of magnitude you often can't get more granular than the millions place). Second, there's an amount of "rounding error" inherent in using floating-point numbers, with the inherent conversion to binary and back; this can cause errors in calculations requiring exact precision (such as when dealing with money), and so unless the extreme magnitude of a floating-point type is required, it's generally recommended to use a method of representation that does not introduce error.

share|improve this answer
    
This is a thorough answer, but I don't think the OP was asking about computer implementations. –  LarsH Feb 12 '13 at 21:36
1  
Although, what the OP is asking about is a typographic representation of numbers, which is very close to computer representation. Binary and decimal are just ways we can write down numbers with a pencil, and computer representations are how we write numbers into a memory with ones and zeros. –  Kaz Feb 13 '13 at 3:25

Just do long division!

11 | 10011 | 110.0101...
      1100
      ----
       111
       110
       ---
         100
          11
         ---
           100
            11
           ---
             1 (repeats)

So 10011 / 11 = 110.0101... (aka 19 / 3 = 6.33...)

Binary long division is a bit longer than decimal long division since you need more digits to write each number, but finding the largest multiple of your divisor that will fit is pretty trivial when it's either 0 or 1 times.

share|improve this answer

0.01 in binary is 0.25 in decimal

share|improve this answer

use the euclidean algorithm, like for the integers

share|improve this answer
    
The Euclidean Algorithm is usually used to find greatest common factors and continued fractions, not to divide or convert bases. –  robjohn Feb 12 '13 at 19:26
    
@robjohn: You use the euclidean algrotihm to express fractions in lowest terms. The OP asked about base 2 fractions, not other representations, so it's clear this answer is a valid response. It's also clear the OP intended to ask about other representations and just didn't use the right terms, so being pedantic is missing the point, but talking about the euclidean algorithm isn't as unrelated as you imply. –  ex0du5 Feb 12 '13 at 20:46
    
@ex0du5: Since the OP mentioned converting $1/4$ to $0.25$, it seems that they are interested in converting binary fractions to the format using a binary point. Since Nicolò said "like for the integers", it really doesn't seem as if he was trying to reduce fractions to lowest terms. –  robjohn Feb 12 '13 at 21:17
    
@ex0du5: I was not being pedantic; I was concerned that Nicolò was using the wrong term for the repeated-division method for converting bases (which is generally used for integers) as shown in the answers to these questions: Converting decimal (base 10) numbers to binary by repeatedly dividing by 2, Convert numbers from one base to another using repeated divisions –  robjohn Feb 12 '13 at 21:19
    
@robjohn: Yes, that's exactly what I said. I said that the answer Nicolo wrote was addressing what was asked, but "It's also clear the OP intended to ask about other representations and just didn't use the right terms". I was the one who had a pedantic point that Nicolo's answer was relevant as stated. I didn't call you pedantic. I just pointed out your comment on the euclidean algorithm didn't seem to understand why it was relevant here. –  ex0du5 Feb 14 '13 at 18:59

not sure how helpful this is but whenever i work with binary I always use a table

so you wanted 0.25 (base 10) in to binary:

binary table

8 4 2 1 . 1/2 1/4 1/8 1/16
8 4 2 1 . 0.5 .25 .125 .0625
0 0 0 0 . 0 1 0 0 (0.25 in binary)
1 1 1 1 . 1 1 0 0 (15.75 in binary)

etc

and the other way

15.375 to binary for example

15 - 8 = 7 (1)
7 - 4 = 3 (1)
3 - 2 = 1 (1)
1 - 1 = 0 (1)
.
0.375 - (1/2) = 0.375 - 0.5 = -0.125 (0)
0.15 - (1/4) = 0.375 - 0.25 = 0.125 (1)
0.125 - (1.8) = 0.125 - 0.125 = 0 (1)

giving: 1111.011

hope this helps

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.