|
-
Jan 30th, 2002, 11:44 AM
#1
perl
How can I convert a decimal number to hex and assign the result to a scalar?
-
Jan 30th, 2002, 12:08 PM
#2
Addicted Member
perl -e "printf(\"%x\", 31);"
will give you your conversion from decimal to hex.
So try:
$scalar = sprintf("%x", $decimal);
cudabean
-
Jan 30th, 2002, 02:07 PM
#3
-
Jan 30th, 2002, 02:10 PM
#4
Sorry, forgot.
One more thing.
How do I expressing negative decimal numbers in hex format?
-
Jan 30th, 2002, 03:57 PM
#5
Addicted Member
Perl does it for you. Try it.
cudabean
-
Jan 30th, 2002, 04:39 PM
#6
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.
-
Jan 30th, 2002, 06:36 PM
#7
Addicted Member
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
-
Jan 30th, 2002, 07:25 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|