in reply to Re^3: decimal to binary conversion need help
in thread decimal to binary conversion need help

By the time it shows up as an argument to your subroutine, it's not decimal any more. It's just a "number". In fact, internally, it's either a binary integer, or an IEEE floating point value (except on exotic hardware). There's no decimal there.

Now, if your routine took a string, and then did the "multiply by 10 and add the next digit" trick for the entire string, then you'd be converting "decimal to number to binary".

And yes, this does make a difference. It helps to understand that Perl is not thinking in decimal, especially when it comes to floating point values (the 10 * 0.1 != 1.0 problem).

So, even if you wanna sweep it under the rug, my followup is to help inform others that are reading, so that they can be accurate in their understanding and assistance.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • Comment on •Re^4: decimal to binary conversion need help

Replies are listed 'Best First'.
Re^5: decimal to binary conversion need help
by thor (Priest) on Jan 06, 2005 at 20:09 UTC
    I don't think you're understanding my point. Numbers are little more than their representation. 16 == 0x10 == 020 == 0b10000. All of those represent sixteen of something. Some representations are more convenient in certain circumstances than others. Perhaps you would have been satisfied if ambrus would have called his subroutine "decimalrepresentation2binaryrepresentation", as this is most accurate. However, I'd need to take a nap after typing such a subroutine name, so I'd shorten it, just as he did. And I think that most people understand what that subroutine does.

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

Re^5: decimal to binary conversion need help
by ambrus (Abbot) on Jan 06, 2005 at 21:09 UTC
    By the time it shows up as an argument to your subroutine, it's not decimal any more. It's just a "number".

    This is wrong, as I've just pointed out in my other answer. In my subroutine, it is a string.