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?
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
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 491 |
Nodes: | 16 (2 / 14) |
Uptime: | 81:38:07 |
Calls: | 9,679 |
Calls today: | 3 |
Files: | 13,722 |
Messages: | 6,173,209 |
Posted today: | 3 |