/    Sign up×
Community /Pin to ProfileBookmark

i am new to the whole bitwise stuff, i have found a means to do a left rotate

[code=php]// rotates the bits in x left n bits
function left_rotate($x, $n)
{
return ($x << $n) | (($x & 0x80000000) ? (($x >> 1) & 0x07fffffff | 0x40000000) >> (31 – $n) : ($x >> 32 – $n));
}[/code]

, but have not found a means to do a right rotate, how can this be done

thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@BeachSideJun 25.2005 — OOPS! My bad! Wrong thread... Sorry!
Copy linkTweet thisAlerts:
@ShrineDesignsauthorJun 26.2005 — i got this[code=php]// rotates bits in x to the right n bits
function right_rotate($x, $n)
{
return ($x >> $n) | ($x << (32 - $n));
}[/code]
i don't think it is working correctly, i am using this in a sha-256 function and the resulting hash is not the same as other hashes return by other people functions, example[code=php]echo sha2('abc'); // outputs: bd706453f1f2dcddc9b6cddbb8f652cd0f69e3209829117cdcaaaae9dcaedc63[/code]and the one here: http://forums.devnetwork.net/viewtopic.php?t=31069 returns ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

i don't know which is correct lol
×

Success!

Help @ShrineDesigns spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...