Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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 avoiding work at the Monastery: (3)
As of 2014-07-14 00:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (253 votes), past polls