Deutsch English Français Italiano |
<87pltsicl7.fsf@fatphil.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Phil Carmody <pc+usenet@asdf.org> Newsgroups: sci.crypt Subject: Re: Efficient dword bitwise rotate / circular shift using Bash shell ? Date: Sat, 11 May 2024 18:37:40 +0300 Organization: A noiseless patient Spider Lines: 19 Message-ID: <87pltsicl7.fsf@fatphil.org> References: <41c2930d8ad16c2b1ecf5263b0dd2ee8$1@sybershock.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sat, 11 May 2024 17:53:28 +0200 (CEST) Injection-Info: dont-email.me; posting-host="58f9969d45a193b121b3ab396f9e3aab"; logging-data="2228599"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Cqh6DC8z7nHVrzgsjn+E6" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cancel-Lock: sha1:0ZuA9JeQOm2zhct5aXE1ea+Yagk= sha1:Sb72BD1vl0vMl9W9lYWuKlDEhH0= Bytes: 1666 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/