print a number in hex

print a number in hex

am 07.10.2007 14:31:32 von 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

Re: print a number in hex

am 07.10.2007 14:45:49 von Don Piven

Amir wrote:
> 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?

printf and sprintf are your friends.

Re: print a number in hex

am 07.10.2007 17:15:12 von Paul Lalli

On Oct 7, 8:31 am, Amir wrote:
> 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

Re: print a number in hex

am 07.10.2007 19:51:02 von Amir

On Oct 7, 5:15 pm, Paul Lalli wrote:
> On Oct 7, 8:31 am, Amir wrote:
>
> > 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

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

Re: print a number in hex

am 07.10.2007 20:01:58 von Paul Lalli

On Oct 7, 1:51 pm, Amir wrote:

> 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

Re: print a number in hex

am 08.10.2007 11:24:06 von Michele Dondi

On Sun, 07 Oct 2007 17:51:02 -0000, Amir wrote:

>I have one more question,

Then you'd better start a new thread...


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^ ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,