print a number in hex

A

Amir

Hi,
I have a variable let's say $address, I would like to print it , but
in its Hex value and not Decimal, how can I do it?
thanks a lot !
-Amir
 
P

Paul Lalli

I have a variable let's say $address, I would like to print it ,
but in its Hex value and not Decimal, how can I do it?

Use printf() (or sprintf()), using either the %x or %X format
specifier:

$ perl -e'printf("%X\n", 30)'
1E

Paul Lalli
 
A

Amir

Use printf() (or sprintf()), using either the %x or %X format
specifier:

$ perl -e'printf("%X\n", 30)'
1E

Paul Lalli

thanks guys,
I have one more question,
I have this code:
$address = ($address & zero_bits(3,11)) | (($col<<3) & 0xff8);
now, the function zero_bits returns a hex number, but it seems that
perl considers it as a decimal, and calculates wrongly the bitwise.
what should I do?!
thanks again
-Amir
 
P

Paul Lalli

I have this code:
$address = ($address & zero_bits(3,11)) | (($col<<3) & 0xff8);
now, the function zero_bits returns a hex number,

No. Perl does not return hex nor decimal. It returns numbers.
"hex" and "decimal" and "octal" are simply ways of displaying
representations of numbers.
but it seems that
perl considers it as a decimal, and calculates wrongly the bitwise.
what should I do?!

You should do what the Posting Guidelines tell you to do - create a
short-but-complete script that demonstrates your problem, and post
that.

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top