On 2024-05-11 17:37, Phil Carmody wrote:
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
rol13() { printf '0x%X' $(((($1<<13)+($1>>19))&0xffffffff))
}
Avoids that limitation, but may be slightly slower depending on bash inefficiencies.
Enjoy
Jakob
--
Jakob Bohm, CIO, Partner, WiseMo A/S.
https://www.wisemo.com
Transformervej 29, 2860 Søborg, Denmark. Direct +45 31 13 16 10
This public discussion message is non-binding and may contain errors.
WiseMo - Remote Service Management for PCs, Phones and Embedded
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)