Sujet : Re: Efficient dword bitwise rotate / circular shift using Bash shell ?
De : pc+usenet (at) *nospam* asdf.org (Phil Carmody)
Groupes : sci.cryptDate : 11. May 2024, 16:37:40
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87pltsicl7.fsf@fatphil.org>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
SugarBug <
3883@sugar.bug> writes:
Example:
>
rol() { num="$@" ; pre=$((num<<13)) ; suf=$((num>>19)) ;
num=$((pre^suf)) ; num=$((num&0xffffffff)) ; echo "$num" ; }
>
What tricks will make this more efficient in Bash?
If you can be sure the input will never be 0xffffffff, then this should
work:
rol () { echo "$(($1*8192%0xffffffff))" ; }
Phil
-- We are no longer hunters and nomads. No longer awed and frightened, as we havegained some understanding of the world in which we live. As such, we can castaside childish remnants from the dawn of our civilization.-- NotSanguine on SoylentNews, after Eugen Weber in /The Western Tradition/