c++ - Why would you use Bitwise operators? -


this question has answer here:

so i'm in process of learning c++ via book 'sams teach c++ in 1 hour day'. far it's been great - i've understood that's said , have managed use of them in simple programs practice them.

however got section on bitwise operators , stumped. understand have &, ~, |, <<, >> etc, , understand each 1 performs different action upon number in binary form, ~ flips numbers over.

the problem have can't head around how , why you'd want use them. it's me being take int, flip binary digits on , have number, how me in way shape or form? i'd appreciate explanation why you'd use each one, , if possible maybe example?

thanks everyone!

there lot of applications, here 2 examples. suppose have 8 one-bit values stored in one-byte container. bitwise-and power of 2 access individual bits easily.

if you're scanning high intensity pixels in rgb image, can use bitwise-and 128 against 3 color values; that's faster operation boolean expression r>128.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -