in reply to Re: convert to binary number
in thread convert to binary number

No, it's not. It's a number, and the OP really does want to convert it to binary. Binary is a text representation of a number just like decimal, octal and hexadecimal.

Replies are listed 'Best First'.
Re^3: convert to binary number
by Anonymous Monk on Jun 06, 2017 at 05:16 UTC
    It's electrons caught in little bits of silicon, pretending to be bits, pretending to be numbers.
Re^3: convert to binary number
by Lotus1 (Vicar) on Jun 07, 2017 at 13:17 UTC

    I was surprised by your statement "No, it's not. It's a number, ...". You were responding to my assertion that the integer was already in binary and could be printed in different bases with printf. Yes, an integer is a number but that doesn't mean it is not stored as binary in memory. Are you referring to assigning a number to a scalar variable such as my $num = 42 ?

    According to perlnumber an integer is represented in Perl as a native integer according to the C compiler used to build Perl. Maybe I have assumed Perl is more like C than it really is. I was referring to how it is stored in memory and that you can use printf to display the value in other bases or even in binary.

    The OP was vague and didn't provide examples so I'm wondering how to know what the OP really wanted.

      You were responding to my assertion that the integer was already in binary and could be printed in different bases with printf.

      I was responding to your assertion that no conversion was required. I wasn't responding to your contradictory assertion that printf could perform the required conversion.

        I was responding to your assertion that no conversion was required. I wasn't responding to your contradictory assertion that printf could perform the required conversion.

        If an integer in memory is in binary and is displayed as binary by printf is there a conversion? If you are talking about converting strings that represent numbers from one base to another that would be something different since the OP specifically mentioned an integer.

        From your original response:

        No, it's not. It's a number, and the OP really does want to convert it to binary.

        You still haven't explained how you know what the OP really wants since they didn't specify. I would like to hear more about how integers in Perl are just numbers.