Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Implement Arithmetic Shift Right for signed number in perl

by choroba (Canon)
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
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
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 studying the Monastery: (9)
As of 2015-07-31 05:44 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 (274 votes), past polls