IMG

 
IMG
IMG   IMG
  Welcome to GTAForums! Be sure to check out the Grand Theft Auto V Forum.

You are not registered! (If you are, click here to login) Registering is fast, free and easy and allows you to instantly reply to any topic on GTAForums.
Why wait? Click here to register your own unique username and become part of the ever-growing community!


( Log In | Register | Revalidate Validation E-mail )
Quick Log-In:
  IMG
       
>
  Reply to this topicStart new topicStart Poll

 Bitwise operators

 
Swoorup  
Posted: Saturday, Apr 7 2012, 15:54
Quote Post


innovator
Group Icon
Group: Members
Joined: Oct 28, 2008

au.gif

XXXXX



What are bitwise operators exactly used for? What are its applications and in what specific applications is it implemented? I fairly know that they are used for manipulating individual bits. But I want to know how are they implemented mostly and what advantages and disadvantages they provide.
PMMSNYahoo
  Top
 

 
K^2  
Posted: Tuesday, Apr 10 2012, 02:15
Quote Post


Vidi Vici Veni
Group Icon
Group: Zaibatsu
Joined: Apr 14, 2004

us.gif

Member Award




Masking, flags, whatever. There are a bunch of uses. Flags is the most straightforward and common. Say you have a bunch of boolean values to store. Keeping a variable for each is a pain. Instead, you can keep a single integer value, and have it hold 32 boolean values. How do you access individual bits for that? Bitwise operations. Say you declared it as "int flags;". If you want to read the flag 3rd bit, just use (flags & 0x4). Alternatively, if you need to compute the flag position, you can use shifts. (flags & (1<<3)) does the same thing. Setting a flag can be done with OR. flags|=0x04. Or you can specify a bunch of flags at once. flags=0x01|0x04|0x10. Typically, you'd have defines for each of these, so flags are named rather than numbered.

Another common thing is encoding/decoding compressed streams. Data in these usually has variable bit length, so a symbol may start in one byte and end in another. Then you need to pull specific bits to reconstruct the symbol. For specific examples, you can take a look at Deflate algorithm used in Zip, GZip, PNG, etc. Or for something a little more straight forward, GIF image encoding.
PMMSN
  Top
 

 

0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)

0 Members:

Topic Options Reply to this topicStart new topicStart Poll
Search topic for posted by (exact match)



 
IMG IMG