Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Implement Arithmetic Shift Right for signed number in perl

by choroba (Abbot)
on Apr 22, 2013 at 23:59 UTC ( #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.
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Implement Arithmetic Shift Right for signed number in perl
Download Code
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
Node Status?
node history
Node Type: note [id://1030002]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (14)
As of 2014-12-22 18:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (126 votes), past polls