--- In [email protected], Paul Herring <pauljherr...@...> wrote:
>
> On Fri, Feb 20, 2009 at 2:43 PM, rodavilaca <rodavil...@...> wrote:
> > Hi,
> >
> > First, sorry for my English.
> >
> > I want to use operator << or >> to run a bit all positions of a char
> > variable. My problem is when the bit reaches the end of the variable.
> > When I use the operator again, the variable char clear all bits of the
> > variable.
> > Example:
> > c = 1 (00000001)
> > c = c <<1;
> > then c = 2 (00000010)
> > c = c <<1;
> > then c = 4 (00000100)
> > ...
> > then c = 128 (10000000)
> > c <<1;
> > then c = 0 (00000000)
> >
> > I want in this time that the variable c is not zero but return c = 1,
> > to begin the process ...
> > How to do this without having to check the condition c == 128 and then
> > do c = 1?
> > Is there some automated way?
> 
> Even with your example, it's not clear what you're trying to do; is it
> a loop? Keep going until you've moved the last bit out?
> 
> c = 1; // or whatever
> while ( c <<= 1){
>    // do whatever with c
> }
> // reaches this point when the last bit is cleared.
> 
> Keep going until there's a 1 in the leftmost position? (i.e. same as
> before but one less iteration):
> while ( (c <<= 1) && (c << 1)){
> //...
> }
> 
> -- 
> PJH
> 
> http://shabbleland.myminicity.com/ind
> http://www.chavgangs.com/register.php?referer=9375
>i not understand when c==128
how c<<1;give result c=0
 acc to me
interger val stored 2 bytes memory space i.e 16bits
when c==128,then
c<<1;
c=256
but if c==16384,then
c=c<<1;
c=-23768
bcoz range of int is frm 23767 to -23768
n leftmost bit reserved for signify sign in signed bit n 0 in unsigned
bit.
plz explain ur prblem clearly.

Reply via email to