Results 1 to 8 of 8

Thread: perl

  1. #1
    imbue
    Guest

    perl

    How can I convert a decimal number to hex and assign the result to a scalar?

  2. #2
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    perl -e "printf(\"%x\", 31);"

    will give you your conversion from decimal to hex.

    So try:
    $scalar = sprintf("%x", $decimal);

    cudabean

  3. #3
    imbue
    Guest
    Thanks. It works good.

  4. #4
    imbue
    Guest

    Sorry, forgot.

    One more thing.
    How do I expressing negative decimal numbers in hex format?

  5. #5
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    Perl does it for you. Try it.

    cudabean

  6. #6
    imbue
    Guest
    yeah I know that.
    I am working on some coding for my shareware app that uses the hard drive serial number. I dont know a lot about hex or perl. I must write a perl script so when people buy my software they get their unlock code quick.
    My code messes up on negative numbers and i am just wondering how to even show a neg in hex.

  7. #7
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    So, when you do this:
    perl -e "printf(\"%x\", -31);"

    You get:
    ffffffe1

    Right?

    ffffffe1 is a really really big number, except when you're talking signed integers. "Signed integers" means the way that most computers internally represent integers.

    When you have signed integers, the left-most bit (MSB) is the sign bit, but it's not as simple as turning the sign bit on in order to convert the number to negative. To negate a number you take the two's compliment of it.

    There are no doubt better tutorials on the web than my ramblings here.

    cudabean

  8. #8
    imbue
    Guest
    yeah I was getting lots of fffff. It was really annoying because i need to keep the number down to 8 digits. Thanks for all your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width