-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/8/10 13:48 , Michael Tiernan wrote:
> ----- "Tom Limoncelli" <t...@whatexit.org> wrote:
>> I see this in code now and then:
>>                 1<<16-1
> 
> Being just a system geek and not a professional programmer, I don't 
> understand why one would use that notation instead of the more obvious 
> variations of "0x8000"?
> I understand that the compiler, at compile time (not run time) will figure 
> out that the programmer "meant" 0x8000 from that piece of code so the end 
> result is the same but it seems that for documentation purposes it'd be more 
> obvious to do it the other way.
> Am I missing something?

I see it as a matter of self-documentation; "0x8000" suggests a magic number
of some kind, which is probably related to bits or to hardware control,
whereas "1<<(mumble)" explicitly says "this is a bit".  (The former might be
a bit *mask*, or not linked to particular bits at all, for example a value
written to a control register where the register isn't documented at the bit
level but only the acceptable values.)  Also, the "1<<n" syntax helps when
you are coding to a specification which describes things in terms of bit
numbers (e.g. "bit 0 controls the transmit register").

- -- 
brandon s. allbery     [linux,solaris,freebsd,perl]      allb...@kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university      KF8NH
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyv52wACgkQIn7hlCsL25WN4wCghwyD0hLGLaV8P4UDUXtOj1S8
KCsAoK4S6h/DBs4G7pp/WDRKkds844wn
=/va/
-----END PGP SIGNATURE-----
_______________________________________________
Tech mailing list
Tech@lopsa.org
http://lopsa.org/cgi-bin/mailman/listinfo/tech
This list provided by the League of Professional System Administrators
 http://lopsa.org/

Reply via email to