[Tutor] Magic numbers

Dennis Lee Bieber wlfraed at ix.netcom.com
Thu Aug 5 13:34:07 EDT 2021


On Thu, 5 Aug 2021 16:59:07 +0100, Alan Gauld <learn2program at gmail.com>
declaimed the following:

>
>On 05/08/2021 16:11, Dennis Lee Bieber wrote:
>> On Thu, 5 Aug 2021 17:48:02 +1000, Phil <phillor9 at gmail.com> declaimed the
>> following:
>>
>>> 128 is bit 7, in this example, of an 8 bit number.
>> 	But what is /significant/ about bit-7 (and are you counting bits
>> starting from 0, or from 1. It matters for documentation since when
>> counting from 0, bit-7 is the /eighth/ bit in the byte).
>
>And this is exactly why bit-shifting is a fault-prone technique only to
>be used in extremis!
>
>:-)

	Doesn't help that the OP isn't using bit shift operators, but instead
is using an exponentiation operator -- which may invoke heavy (relatively
speaking) math operations vs a direct shift.

	1 << 0 

feels more explicit than

	2 ** 0


>>> 1 << 7
128


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Tutor mailing list