mathemetika+ Posted May 5, 2015 Posted May 5, 2015 (edited) Trying to understand the fundamentals of binary rather than just following steps, I wanted to know why do we multiply by 2 to convert a decimal ([latex]0.5[/latex], [latex]0.25[/latex]) to a binary and why do we divide by [latex]2[/latex] when we want to convert a whole number [latex](200)[/latex] by [latex]2[/latex]? Obviously, it works but how ?Take the following example:Convert [latex]200_{10}[/latex] to binary: Solution: D > B | Remainder ------------------------------------- 200 / 2 = 100 | 0 100 / 2 = 50 | 0 50/2 = 25 | 0 25/2 = 12 | 1 12/2 = 6 | 0 6/2 = 3 | 0 3/2 = 1 | 1 1/2 = 0 | 1 By taking the remainder from **bottom-to-top**[latex]200_{10} = 11001000_2[/latex]> Why this method works ? In other words, what's the secret behind the division by [latex]2[/latex] ? Now converting decimals (e.g. [latex]0.5[/latex], [latex]0.25[/latex]) to binary:Now Suppose we have a decimal like [latex]0.25[/latex] and we want to convert it to binary, one of the method which I know goes like this:Multiplying the decimal by [latex]2[/latex] repeatedly: 0.25 * 2 = {0}.50 | {0} 0.50 * 2 = {1}.00 | {1} 0.00 -------------------------- .01 0.01 For more details about the above method: Decimal to binary conversion with fractionYou can see the the two operations are **reversed**, to convert a whole number to a binary we divide by[latex] 2[/latex] and to convert a fraction (decimal) we used multiplication. Add to that the order in which we take the result from bottom-to-top and from top-to-bottom. How that works?>(Why division used to convert whole numbers to binary and why multiplication used to convert decimals (e.g. 0.25) to binary?) How These procedures work ? Edited May 5, 2015 by mathemetika+
EdEarl Posted May 5, 2015 Posted May 5, 2015 I do not know what you need to satisfy your question, because you have presented all the evidence I need to answer your question for myself. Thus, the only things I can say are obvious, for example there are two values in each bit of a binary number, either 0 or 1, and dividing a whole number by 2 always gives a remainder of either 0 or 1, and multiplying a fraction by 2 gives a whole number of either 0 or 1 plus a fraction. Moreover, the number 2 is the only number that gives the correct answer. If you can precisely explain what is is you do not understand, I might understand what you need.
mathemetika+ Posted May 5, 2015 Author Posted May 5, 2015 (edited) I do not know what you need to satisfy your question, because you have presented all the evidence I need to answer your question for myself. Thus, the only things I can say are obvious, for example there are two values in each bit of a binary number, either 0 or 1, and dividing a whole number by 2 always gives a remainder of either 0 or 1, and multiplying a fraction by 2 gives a whole number of either 0 or 1 plus a fraction. Moreover, the number 2 is the only number that gives the correct answer. If you can precisely explain what is is you do not understand, I might understand what you need. What I don't understand is simply, why when we divide by two it shifts bits to the right (remainders) and when we multiply by 2 it shift bits to the left (the whole part) Edited May 5, 2015 by mathemetika+
Endy0816 Posted May 5, 2015 Posted May 5, 2015 Think in terms of places. For decimal 10ths 100ths 1000ths For binary halves quarters eighths .25 ➡ 1/4 ➡ .01(binary)
mathemetika+ Posted May 5, 2015 Author Posted May 5, 2015 I tho When we divide by [latex]2[/latex], what happens is simply shifting bits to the right side. For example: [latex]19_{10} = 10011_{2}[/latex] To convert the decimal 19 t0 binary we divide by two, but watch what happens at each time: *r = remainder 19 / 2 = 9 r 1 | 1001.1 < r 9 / 2 = 4 r 1 | 100.1 < r 4/ 2 = 2 r 0 | 10.0 < r 2/2 = 1 r 0 | 1.0 < r 1/2 = 0 r 1 | .1 < r Each time we divide by [latex]2 [/latex] we move [latex]1[/latex] bit to the right-hand side successively until we run out of bits, just like in the previous example. In terms of converting fractions to binary (e.g. [latex]0.5[/latex], [latex]1.039[/latex]) we use the inverse operation (rater than division, we use multiplication). In this process each time we multiply by [latex]2[/latex], we shift the bits to the left-hand side. I hope the way I explained it, shows that I understood the concept myself. If you think there's an error please correct me.
MonDie Posted May 5, 2015 Posted May 5, 2015 It works because binary, as a base-two system, is based on powers of 2. in base two 1 = 2^0 10 = 2^1 100 = 2^2 ... in base ten 1 = 10^0 10 = 10^1 100 = 10^2 ... 1
EdEarl Posted May 5, 2015 Posted May 5, 2015 This is a good lesson on binary-decimal conversion. However, it does not answer the Topic Question, "Why do we divide or multiply by 2 when converting binary?" Moreover, generally science cannot answer, "Why something?" One can either learn by rote or intuition some text, process, image or emotion. Often, a person who learns some thing by rote may later have an epiphany, and suddenly intuit the thing. It's a process of understanding, and occasionally a person understands something novel, which documented becomes part of our collective knowledge. 1
mathemetika+ Posted May 5, 2015 Author Posted May 5, 2015 This is a good lesson on binary-decimal conversion. However, it does not answer the Topic Question, "Why do we divide or multiply by 2 when converting binary?" Moreover, generally science cannot answer, "Why something?" One can either learn by rote or intuition some text, process, image or emotion. Often, a person who learns some thing by rote may later have an epiphany, and suddenly intuit the thing. It's a process of understanding, and occasionally a person understands something novel, which documented becomes part of our collective knowledge. You're very right. This feeling always comes to me and it always holds me back from learning. I always want to delve into details, I can't be unreasonable. Well, we as humans repeat things most of the time without understanding (without conciousness). I remeber a study on apes (bonobos) on the way they learn compared with the way we learn. I turned out (bonobos) don't just repeat what the others do ! Somehow they do it for a reason, but when the researcher compared their result with a child, it turned out the opposite, repeating and no logical thinking of the behavior. You can simply think of that and prove it to yourself, imagine a child grown in a society let's say in that society each individual unrinate on the street as urinating is not ritual inside homes, just assuming that, you would think that child be different ? absolutely not, at least for the period of his childhood. So repeating is our way of learning, but we suffer if we think of logic. You may agree with me.
EdEarl Posted May 5, 2015 Posted May 5, 2015 So repeating is our way of learning, but we suffer if we think of logic. You may agree with me. I think you mean that we suffer frustration if we try to use logic to understand something we are not ready to understand. Yes, that can happen, but sometimes we can use logic to understand better. However, we can make mistakes and come to an incorrect conclusion using logic. We need to test logical results against reality.
MonDie Posted May 5, 2015 Posted May 5, 2015 This is a good lesson on binary-decimal conversion. However, it does not answer the Topic Question, "Why do we divide or multiply by 2 when converting binary?" Moreover, generally science cannot answer, "Why something?" One can either learn by rote or intuition some text, process, image or emotion. Often, a person who learns some thing by rote may later have an epiphany, and suddenly intuit the thing. It's a process of understanding, and occasionally a person understands something novel, which documented becomes part of our collective knowledge. I don't think I agree with this. Mathematicians offer proofs all the time.
EdEarl Posted May 5, 2015 Posted May 5, 2015 I don't think I agree with this. Mathematicians offer proofs all the time. OK, except for math and logic proofs.
Acme Posted May 5, 2015 Posted May 5, 2015 ... So repeating is our way of learning, but we suffer if we think of logic. You may agree with me. Suffer is such a subjective term. I will only agree with you when I see Bonobos writing up questions on number theory. in base two 1 = 2^0 10 = 2^1 100 = 2^2 ... in base ten 1 = 10^0 10 = 10^1 100 = 10^2 Notably, as you move past base ten you must add a new character for every addition. E.g. base eleven requires 11 characters, 0-9 and [usually] A. Then so on adding characters... In regards to the OP and converting bases the math is as you remark, but in a practical sense working in higher bases demands learning new numerals which complicates not only calculations but knowing the value of a numeric string.
Endy0816 Posted May 5, 2015 Posted May 5, 2015 (edited) You are using division to determine what value needs to be in which position with a different base. 21 = 2 * 101 + 1 * 100 Using modulus instead of 'remainder of' because this just makes the world a better place... 21 mod 2 = 1 -> Place 1 in the One's place 10 mod 2 = 0 -> Place 0 in the Two's place 05 mod 2 = 1 -> Place 1 in the Four's place 02 mod 2 = 0 -> Place 0 in the Eight's place 01 mod 2 = 1 -> Place 1 in the Sixteen's place 21 -> 10101 1 * 24 + 0*23 + 1*22 + 0 * 21 + 1 * 20 = 1 + 4 + 16 = 21 Don't necessarily have to do it this way though. Could just as well do: 21 - 16*1 - 8*0 - 4*1 - 2*0 - 1*1 = 0 Find the highest that will fit, subtract that. Find the next highest that will fit, subtract that and so on, until you reach zero. Any you were able to subtract receive a 1 any that you didn't receive a zero. Just a bit more difficult, especially as the number being converted grows. Edited May 6, 2015 by Endy0816 1
Sensei Posted May 6, 2015 Posted May 6, 2015 (edited) I wanted to know why do we multiply by 2 to convert a decimal ([latex]0.5[/latex], [latex]0.25[/latex]) to a binary and why do we divide by [latex]2[/latex] when we want to convert a whole number [latex](200)[/latex] by [latex]2[/latex]? Obviously, it works but how ? Dividing can be replaced by multiplication by value power negative exponent. f.e. 23=8 22=4 21=2 20=1 2-1=1/2=0.5 2-2=1/4=0.25 2-3=1/8=0.125 To convert decimal to binary you don't need to multiply or divide. It's just one of algorithms. See this: unsigned int value = 65535; // value to show as binary for( unsigned int i = 31; i >= 0; i-- ) { unsigned int x = 1<< i; // equivalent to 2^i if( value > x ) { value -= x; printf( "1" ); } else { printf( "0" ); } } Edited May 6, 2015 by Sensei
MonDie Posted May 6, 2015 Posted May 6, 2015 1 * 24 + 0*23 + 1*22 + 0 * 21 + 1 * 20 = 1 + 4 + 16 = 21 It's the base-two equivalent of scientific notation.
Strange Posted June 1, 2015 Posted June 1, 2015 This is a good lesson on binary-decimal conversion. However, it does not answer the Topic Question, "Why do we divide or multiply by 2 when converting binary?" Moreover, generally science cannot answer, "Why something?" One can either learn by rote or intuition some text, process, image or emotion. Often, a person who learns some thing by rote may later have an epiphany, and suddenly intuit the thing. It's a process of understanding, and occasionally a person understands something novel, which documented becomes part of our collective knowledge. But the "why" in this case is very clear: decimal is based on powers of 10 (and so we multiply/divide by 10) and binary is based on powers of 2 (and so we multiply/divide by 2).
Keen Posted June 12, 2015 Posted June 12, 2015 I'm not sure you will be satisfied with my answear, but I can give you a proof of why this works. If you take a general number n, that you want to write in binary, you can write n=2q+r with q being the quotient and r the remainder in division by 2. Now if you have q in binary, let's say for example it's equal to 10100, then it's very easy to obtain 2q in binary as well, since multiplying by two is simply adding a 0 to the end of the binary notation, so 2q in binary would be 101000. Now you simply have to calculate 2q+r, which is fairly simple and you obtain that n is either 101001 or 101000. Usually you don't have q in binary, so what you can do is write q=q1*2+r1 with q1 the quotient ad r1 the rest, If you had q1 in binary, you can get q just as easily as before, if you don't, you simply iterate the process. At some point you will get to some quotient which is either 1 or 0, so its binary is known. The conversion you described above is simply a recursive algorithm , which works, because the quotient is getting smaller and smaller and the fact, that multiplication by 2 in binary simply corresponds to adding 0 to the end.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now