what do you mean?
use this operation when you need to use it and why? becuz you need it... :-D
when you want to do some bit level job you have to use this operation for example when you want to retreive the binary equivalent of an integer or when you want to write a sequence of bit in to a file or somthin like that...
when you want to do some bit level job you have to use this operation for example when you want to retreive the binary equivalent of an integer or when you want to write a sequence of bit in to a file or somthin like that...
Alright then, here's your challenge, sourena: give me a psudo-code example of when one would use a bitwise shift operation in fetching the binary equivalent of an integer or writing a sequence of bits into a file. I'm telling you, it doesn't look like the bitwise shift operation does what you think it does.
Example A is inaccessible, but the URL says using-bitwise-and, so I'm a bit suspicious.
Example B... well... admittedly I did not consider that maybe someone would want to use this particular method. Using that method, indeed the shift is required. Using an array of booleans, no...
the second bit algorithm is a little slow but it can be better and as you know bitwise operators are so fast and i guess it's better than an array of boolean. especially in compression and encryption we can use bitwise operator for example in BWT (binary wavelet transform) we use only XOR operator which make the bwt so fast...and ofcourse in digital system programming like fpga the only choice in bit operation becuz you work in bit level...
as i said before you can use it anywhere you think it works!!!
Are you so sure? Just because something is fast does not mean it's better. I personally do not think that a dynamically expandable container of booleans in a non-standard library is better than one that is not dynamically expandable yet has elements that can be read individually at any time and do not need to be shifted to be read. It depends on what you need to do. Ideally you can have your cake and eat it too with a bitmap.
actually i am New to C++ so please do not mind in answer my question
Please can u tell me how to solve this question step by step
Write a program which reads an integer value from the keyboard into a variable of type int,
and uses one of the bitwise operators (i.e. not the % operator!) to determine the positive remainder
when divided by 8. For example, 29 = (3x8)+5 and -14 = (-2x8)+2 have positive remainder
5 and 2 respectively when divided by 8.
so kulfi you got the wheel but u dont know how to make a car !!
what is it? your homework?
you write your code , test it and if it doesnt work post it here.
Example B... well... admittedly I did not consider that maybe someone would want to use this particular method. Using that method, indeed the shift is required. Using an array of booleans, no...
This is useful when size matters. For example, in compression programs, this is how the compressed data is stored. Suppose you've managed to make a size reducing mapping that takes a byte value and sends it to a 5-bit value. When you write that 5-bit value you want it to take 5-bits in the file, not 1 byte, or else what kind of compression would that be? The problem is that you can only write to the file multiples of 1 byte per operation. So, what you do is the following:
Let's say you have 5-bit values stored as bytes:
---11010, ---10110, ---11101, ---10000, etc...
(we only care about the 5 least significant bits)
You take 8 of them and pack them using shift and other bitwise operations:
11010101101110110000...
The result is exactly 5 bytes long. You can now store the compressed data on your hard drive :D