![]() |
News from da outaworlds |
mail files register groups login |
Message-ID: |
Subject | Author |
![]() | SugarBug |
![]() ![]() | Phil Carmody |
![]() ![]() ![]() | Jakob Bohm |
1 |
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?
--
www.sybershock.com | sci.crypt | alt.sources.crypto | alt.lite.bulb
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/
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
1 |