-
February 26th, 2010, 11:12 AM
#1
Bitshift operators
Hi guys,
I'm new to c++ programming. Taking this as a college coarse and i guess my instructor just couldn't explain this well enough for me to truely grasp the purpose of this.
He said that bitshift operators are used alot in writing driver software. Which i can understand. But outside that scope what else are they good for?
I mean it just seems like a meathod of encryption for anything else.
take a number or letter... shift it so many spaces left or right and get a result.... maybe i'm missing the point. Can someone please help out?
example:
int number 16387;
number >>=2;
result: number=4096
The number is translated into binary. 0100000000000011
The bits are shifted 2 to the right to make 0001000000000000
the result becomes 4096.
So unless those bits are controlling the on's and offs of a piece of hardware. I don't see much of a point.
Last edited by cypher5783; February 26th, 2010 at 11:19 AM.
-
February 26th, 2010, 11:18 AM
#2
Re: Bitshift operators
Left-shifting an integer may be faster than multiplying by a power of 2, but on most compilers the difference won't be notable.
The place that shifting is used most often in actual code is when you're formatting data for a file or network socket. Even then, you can get away without doing it explicitly most of the time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|