Computer Science Canada Converting Binary numbers to Decimal using decimal numbers |
Author: | BigBear [ Mon Apr 06, 2009 4:41 pm ] | ||
Post subject: | Converting Binary numbers to Decimal using decimal numbers | ||
I am trying to convert a decimal number with a decimal portion into a binary number with a decimal portion. I have added a lot of variables to try to break it down and get it to work. I have a seperate function for binary to decimal but the decimal portion is different. |
Author: | Tony [ Mon Apr 06, 2009 4:48 pm ] |
Post subject: | RE:Converting Binary numbers to Decimal using decimal numbers |
This doesn't look like IEEE 754 |
Author: | BigBear [ Mon Apr 06, 2009 5:02 pm ] |
Post subject: | RE:Converting Binary numbers to Decimal using decimal numbers |
No it doesn't..... |
Author: | Tony [ Mon Apr 06, 2009 5:08 pm ] |
Post subject: | RE:Converting Binary numbers to Decimal using decimal numbers |
So what kind of format are you going for here? |
Author: | BigBear [ Mon Apr 06, 2009 5:09 pm ] |
Post subject: | RE:Converting Binary numbers to Decimal using decimal numbers |
What do you mean by format? |
Author: | Tony [ Mon Apr 06, 2009 5:12 pm ] |
Post subject: | RE:Converting Binary numbers to Decimal using decimal numbers |
How do you want the output to look? What is 5.5 supposed to look like, in binary? |
Author: | BigBear [ Mon Apr 06, 2009 5:22 pm ] |
Post subject: | RE:Converting Binary numbers to Decimal using decimal numbers |
I guess the 5.5 is right. But 5.4 doesn't work and it should be 101.01100110011001 Because exit when count = 14 but that could be changed to four or something. |
Author: | Tony [ Mon Apr 06, 2009 5:25 pm ] |
Post subject: | RE:Converting Binary numbers to Decimal using decimal numbers |
ok, I see the 5. => 101. but how are you going from .4 to .01100110011001 ? |
Author: | BigBear [ Mon Apr 06, 2009 5:32 pm ] | ||
Post subject: | RE:Converting Binary numbers to Decimal using decimal numbers | ||
you take the decimal portion of the number .4 and times it by 2 and the whole number portion is either a 1 or 0 so
then it checks the decimal portion of that new number and sees if it is less than .10 which it will not be because it has a repeating decimal portion of 0110 So it will iterate 14 times (as it sits) so the wholenumber portion will be added to tempdecimal then it will be added to the 101 part |
Author: | Tony [ Mon Apr 06, 2009 5:49 pm ] |
Post subject: | RE:Converting Binary numbers to Decimal using decimal numbers |
so, if I understand... 0.4 * 2 = 0.8 -- record 0 0.8 * 2 = 1.6 -- record decimal 1 as binary 1 ? So the natural question then... how do you convert back to decimal? |
Author: | BigBear [ Mon Apr 06, 2009 6:00 pm ] |
Post subject: | RE:Converting Binary numbers to Decimal using decimal numbers |
But this function doesn't work For decimal you can find how long the decimal portion is and start at a - number and do the div and mod way |
Author: | [Gandalf] [ Mon Apr 06, 2009 6:39 pm ] |
Post subject: | RE:Converting Binary numbers to Decimal using decimal numbers |
wtd's Number Bases Article on the CompSci.ca Wiki. |
Author: | BigBear [ Mon Apr 06, 2009 6:48 pm ] |
Post subject: | Re: RE:Converting Binary numbers to Decimal using decimal numbers |
[quote="[Gandalf] @ Mon Apr 06, 2009 6:39 pm"]wtd's Number Bases Article on the CompSci.ca Wiki.[/quote] Yeah I understand the number systems but I am trying to find something wrong with my function I thibk it is a little thing |
Author: | Insectoid [ Mon Apr 06, 2009 7:36 pm ] |
Post subject: | RE:Converting Binary numbers to Decimal using decimal numbers |
That's the way I use, and the way Dan was taught in 2nd year uni. I still haven't figured out how to convert back, as you are discarding numbers. |
Author: | BigBear [ Mon Apr 06, 2009 7:46 pm ] |
Post subject: | Re: RE:Converting Binary numbers to Decimal using decimal numbers |
insectoid @ Mon Apr 06, 2009 7:36 pm wrote: That's the way I use, and the way Dan was taught in 2nd year uni. I still haven't figured out how to convert back, as you are discarding numbers.
I have finished the function to convert from binary to decimal if that's what you meant by convert back |