The 0xNNNN notation is a source-code feature. It is parsed at compile-time. So this works:
my $n = 0xDEADBEEF; print "$n\n"; # Output: # 3735928559
And this works but you shouldn't use it:
# This works but is NOT recommended, and can be unsafe. my $n = eval "0xDEADBEEF"; print "$\n"; # Output: # 3735928559
That second example works because even though we've created a string of characters, "0xDEADBEEF", the eval statement evaluates that string as source code, so it gets parsed and compiled when the statement is executed at runtime.
This doesn't work:
my $n = "0xDEADBEEF"; print "$n\n"; # Output: # 0xDEADBEEF
It didn't work because the string was taken as plain old characters. Since you want to take a string of characters and interpret them as a hex digits you should use the hex function:
This is the version you should use:
my $string = "DEADBEEF"; my $n = hex($string); print "$n\n"; # Output: # 3735928559
Dave
In reply to Re: hex numbers
by davido
in thread hex numbers
by LloydRice
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |