left shift operator behaves like left rotate when the operand is a variable.
Below is a snippet of code and the result (compiler version also
mentioned). I fail to understand why the left shift operator behaves
as if it were the left rotate operator when the operand is a variable.
$ cat test.c
unsigned int a = 32, b = 33;
printf("with constants 1 << 32 = %u, 1 << 33 = %u\n", 1<<32,
printf("with variables 1 << 32 = %u, 1 << 33 = %u\n", 1<<a, 1<<b);
$ gcc test.c
test.c: In function 'main':
test.c:6:5: warning: left shi...Left Shift / Right Shift Operators
Is there any way to catch the losing bit occurring due to Right Shift
int a = 5 ;
a = a >> 1 ; // // a is now 2 and the least significant bit is lost //
I want this solution for the question:
"How to find if the number is even or odd using only "<<" or/and ">>"
On Thu, 29 Nov 2006, Santosh Nayak wrote:
> Is there any way to catch the losing bit occurring due to Right Shift
> Operator ?
int a = 5;
int lost_bit = a & 1;
a = a >> 1;
/* now lost_bit holds the lost bit */
> ...Java left shift and right shift operators.
I have a problem where I have to do left shift and right shift.
output = N >> shiftby;
Above N is shifted right.
Example if N=11101101 [binary value]
will become: 1110110 when shiftby=1;
will become: 0111011 when shiftby=2;
will become: 0011101 when shiftby=3;
will become: 0001110 when shiftby=4;
will become: 0000111 when shiftby=5;
will become: 0000011 when shiftby=6;
will become: 0000001 when shiftby=7;
When I want to shift left I can use
output = N << shiftby; //[Not change in sign "<<" instead of ">>"]
Above N is shi...Shift operator
Anyone knows how the vhdl shift operator (shr or shl) is implemented?
Ex: out_var := shr(inp_value,inp_shr);
Is it synthesized to a barrel shifter? I guess this requires a lot of
logic, anyone have a rough idea how much area/gates a 32-bit barrel
shifter needs? From the standard "triangle" layout, it looks like the
area grows with a factor 4, so that a 64-bit barrel shifter consumes 4
times as much hardware as a 32 bit. Anyone knows if this is correct?
Lots of questions... : )
Can I suggest using !>> and <<! for right and left rotate operations
"Robert Finch" <firstname.lastname@example.org> wrote in message
> Can I suggest using !>> and <<! for right and left rotate operations
> respectively ?
Suggest away. But this isn't really the best group
for that. The group where the C++ standard and its
future directions are discussed is comp.std.c++.
Here we try to keep the discussion about the language
in its current form.
If i'm shifting an integer 'n' times where n > sizeof(int), It's giving
the same value as
that of n-sizeof(n). Why is it behaving like this. I studied that the
bit 'll be replaced by '0'.
int i = 1;
printf ("%d\n", i<<32);
int i = 2;
printf ("%d\n", i<<33);
Le 14-06-2006, deepak <email@example.com> a �crit�:
> If i'm shifting an integer 'n' times where n > sizeof(int), It's giving
> the same value as
> that of n-sizeof(n). Why is it behaving like this. I studied...Shift Operation
Could you please explain whether C standard supports logical right
shift operation using some operator?
I know somewhere I read about >>> operator. I thought, it is in C but i
think i'm wrong about it. No where google helps me determining this
lapse in my memory. MSVC 6 compiler gives me error.
Thanks && Regards,
> Hi All,
> Could you please explain whether C standard supports logical right
> shift operation using some operator?
C's right shift operator, >>, works like this:
A >> B will yield a result that is...Rotate operators
In xHarbour compiler there are left-shift(<<) and right-shift(>>) operators.
Very good. But in many implementations it can be usefull left-rotate and
right-rotate operators. Especially for data packing/crypting, because no
bit lossing occures.
Well known C compilers have not theese operators and users with assembler
practise in tears remember such good ROL and ROR assembler instructions.
What do you thing about this ?
With best regards,
also in tears
> In xHarbour compiler there are left-shift(<<) and right-shift(>>)
can anyone please tell me how to do a left shift in the folowing
suppose there are 5bits: 10010 now i have to shift left such that 1st
bit should go to the last position i.e 00101. when I use "<<" operator
the last position is appended with 0 i.e 00100. Is there any operator
in verilog to use?
Thanks a lot.
On 5 Jul 2006 00:08:24 -0700, "raghu" wrote:
>can anyone please tell me how to do a left shift in the folowing
>suppose there are 5bits: 10010 now i have to shift left such that 1st