Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Implement Arithmetic Shift Right for signed number in perl

by choroba (Cardinal)
on Apr 22, 2013 at 23:59 UTC ( [id://1030002]=note: print w/replies, xml ) Need Help??


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

What is wrong with
printf '0x%x', -0xaaaaaaaa >> 32;
It gives the expected result.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Implement Arithmetic Shift Right for signed number in perl
by IamAwesom3 (Initiate) on Apr 23, 2013 at 15:15 UTC
    That's not the correct way, It will not be true every time, this time you knew the result. I figured out the correct way
    my $Rm = 0xAAAAAAAA; my $Rd = $Rm >> 31; # any shift amount from 0 top 31 for 32 bit data. $Rd |= 0xffffffff << (32 - 31); #it can be (32 - any shift amount) $Rd = $Rd & 0xffffffff; #mask bits more than 32 printf "Rd = 0x%x\t Rb = %x\n",$Rd, $Rm;
    Output
    Rd = 0xffffffff Rb = 0xaaaaaaaa

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-03-28 11:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found