Re: Efficient dword bitwise rotate / circular shift using Bash shell ?

Liste des GroupesRevenir à s crypt 
Sujet : Re: Efficient dword bitwise rotate / circular shift using Bash shell ?
De : pc+usenet (at) *nospam* asdf.org (Phil Carmody)
Groupes : sci.crypt
Date : 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 have
gained some understanding of the world in which we live. As such, we can cast
aside childish remnants from the dawn of our civilization.
-- NotSanguine on SoylentNews, after Eugen Weber in /The Western Tradition/

Date Sujet#  Auteur
4 May 24 * Efficient dword bitwise rotate / circular shift using Bash shell ?3SugarBug
11 May 24 `* Re: Efficient dword bitwise rotate / circular shift using Bash shell ?2Phil Carmody
15 May 24  `- Re: Efficient dword bitwise rotate / circular shift using Bash shell ?1Jakob Bohm

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal