Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Implement Arithmetic Shift Right for signed number in perl

by Krambambuli (Deacon)
on Apr 23, 2013 at 08:36 UTC ( #1030071=note: print w/ replies, xml ) Need Help??


in reply to Implement Arithmetic Shift Right for signed number in perl

Maybe the following helps a bit clarifying what's what:

#!/usr/bin/perl use strict; use warnings; use Data::Hexdumper qw(hexdump); use integer; my $Rm = '0xAAAAAAAA'; my $Rb = hex $Rm; my $Rc = pack 'l', $Rb; my $Rd = unpack 'l', $Rc; my $Re = $Rd >> 31; my $Rx = pack 'l', $Re; print 'Rm: ', hexdump( $Rm, { suppress_warnings => 1 } ); print 'Rb: ', hexdump( $Rb, { suppress_warnings => 1 } ); print 'Rc: ', hexdump( $Rc, { suppress_warnings => 1 } ); print 'Rd: ', hexdump( $Rd, { suppress_warnings => 1 } ); print 'Re: ', hexdump( $Re, { suppress_warnings => 1 } ); print 'Rx: ', hexdump( $Rx, { suppress_warnings => 1 } ); printf "Rb = 0x%x\t Re = 0x%x\n",$Rb, $Re;
which displays
Rm: 0x0000 : 30 78 41 41 41 41 41 41 41 41 00 00 00 00 00 00 : 0xAAA +AAAAA...... Rb: 0x0000 : 32 38 36 33 33 31 31 35 33 30 00 00 00 00 00 00 : 28633 +11530...... Rc: 0x0000 : AA AA AA AA 00 00 00 00 00 00 00 00 00 00 00 00 : ..... +........... Rd: 0x0000 : 2D 31 34 33 31 36 35 35 37 36 36 00 00 00 00 00 : -1431 +655766..... Re: 0x0000 : 2D 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : -1... +........... Rx: 0x0000 : FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 : ..... +........... Rb = 0xaaaaaaaa Re = 0xffffffffffffffff

Krambambuli
---


Comment on Re: Implement Arithmetic Shift Right for signed number in perl
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030071]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2015-07-07 23:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls