Weird Enumeration

Started by
12 comments, last by adder_noir 13 years, 8 months ago
Quote:That << is raising a power essentially.


Not quite. 2x only applies if the left operand is 1. As stated it's an arithmetic shift left. Take for instance

3 << 2

3 in binary notation is 11. << 2 now means shifting these bits to the left, and filling the right ones with zeroes.

112 << 2 == 11002 == 12 == 3 * 4

a << x is therefore the same like a * 2x.

To clarify: See what happens if you do a shift left with decimals:

3 << 2 == 300 (in decimals) (Edit: typo)


Get familiar with binaries, it's a must for a developer [smile]

[Edited by - unbird on August 26, 2010 9:31:25 AM]
Advertisement
Really interesting thanks guys! I'm ok with binary just still a bit unfamiliar with this way of doing things. I can only see it as a space saver right now I can't visualise the rest of its functionality.

Thanks alot ;o)
Quote:Original post by adder_noir
Really interesting thanks guys! I'm ok with binary just still a bit unfamiliar with this way of doing things. I can only see it as a space saver right now I can't visualise the rest of its functionality.

Thanks alot ;o)


You can do the same sort of thing with bit_structs as well...

struct flags{  uint8_t flag1 : 1;  uint8_t flag2 : 1;  uint8_t flag3 : 1;  uint8_t flag4 : 1;  uint8_t flag5 : 1;  uint8_t flag6 : 1;  uint8_t flag7 : 1;  uint8_t flag8 : 1;};flags f;f.flag1 = 1;f.flag2 = 0;


It's more common to see enums used in this fashion though
Thanks guys! I'd be lying if I said I understood how to use it fully but that's given me alot of help cheers!

This topic is closed to new replies.

Advertisement