Sujet : Re: lun - Lucky Number
De : 333200007110-0201 (at) *nospam* ybtra.de (Marcel Logen)
Groupes : sci.cryptDate : 16. Mar 2025, 12:15:16
Autres entêtes
Organisation : Bureau Logen
Message-ID : <87msdlb59m.fsf@pc-731.ybtra.de>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Richard Heathfield in sci.crypt:
On 15/03/2025 19:44, Marcel Logen wrote:
[...]
Okay. In C, ! is the `not' operator.
I was aware of that. So I thought that the double exclamation
mark was superfluous.
0 is false, 1 is true, non-zero is true, but not true is false. So:
^^^^^^^^^^^^^^^^
This is probably the crucial point.
x = 6;
printf("%d", x); prints 6.
printf("%d", !x); prints 0 because not non-zero is false.
printf("%d", !!x); prints 1 because not not non-zero is true.
>
So !!x maps 0 to 0 and everything else to 1. If you're printing
bits, it's just the job.
A good trick! So a kind of normalization, AFAICS.
[...]
#define BIT_QRY(x,i) ((x[(i)>>3] & (1<<((i)&7)))!=0)
#define BIT_SET(x,i) (x)[(i)>>3]|=(1<<((i)&7))
#define BIT_CLR(x,i) (x)[(i)>>3]&=(1<<((i)&7))^0xFF
[...]
Say i is 77, which is
>
01001101
>
i >> 3 gives us 00001001, or 9.
i & 7 gives us 00000101, or 5.
>
So these macros respectively query, set, or clear bit 5 of byte 9
(counting from x).
>
A somewhat hurried explanation, so feel free to ask further.
I'll take a closer look at this. For now, your explanation is
good enough for me. Thanks.
Marcel
-- Sun Mar 16 12:15:16 2025 CET (1742123716)pc-73187 msdl b59mLines: 52