S
Sanny
I have a problem where I have to do left shift and right shift.
Long N;
int shiftby;
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 shifted left.
Example if N=11101101 [binary value]
will become: 111011010 when shiftby=1;
will become: 1110110100 when shiftby=2;
will become: 11101101000 when shiftby=3;
will become: 111011010000 when shiftby=4;
will become: 1110110100000 when shiftby=5;
will become: 11101101000000 when shiftby=6;
will become: 111011010000000 when shiftby=7;
I have to use use left shift and right shift to shift Number right/
left depending on value of shiftby
if (shift>0) output = N >> shiftby; else output = N << (-shiftby);//
working but inefficient.
I am using above shift operator many times.
I want to get rid of the if then else condition.
As If condition takes a lot of time.
I want something like
output = N >> shiftby; where N is shifted left / right automatically
if shiftby is -ve then shift left otherwise shift right.
I tried using below function
divider=2^shiftby; //<<=== Is it not 2*2* ... shiftby times????
math.pow() can also be used
output = N * divider;// automatically shifts left right depending on
value of divider
But this seems not to work.
math.pow() is again time consuming function. Can I use it? how much
faster is math.pow() function compared to if conditions?
Is there any way to avoid the if condition and do right shift and left
shift using operators depending on shiftby is +ve or -ve?
Bye
Sanny
Java Experts needed
http://www.GetClub.com/Experts.php
[Lots of coding jobs to choose]
Long N;
int shiftby;
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 shifted left.
Example if N=11101101 [binary value]
will become: 111011010 when shiftby=1;
will become: 1110110100 when shiftby=2;
will become: 11101101000 when shiftby=3;
will become: 111011010000 when shiftby=4;
will become: 1110110100000 when shiftby=5;
will become: 11101101000000 when shiftby=6;
will become: 111011010000000 when shiftby=7;
I have to use use left shift and right shift to shift Number right/
left depending on value of shiftby
if (shift>0) output = N >> shiftby; else output = N << (-shiftby);//
working but inefficient.
I am using above shift operator many times.
I want to get rid of the if then else condition.
As If condition takes a lot of time.
I want something like
output = N >> shiftby; where N is shifted left / right automatically
if shiftby is -ve then shift left otherwise shift right.
I tried using below function
divider=2^shiftby; //<<=== Is it not 2*2* ... shiftby times????
math.pow() can also be used
output = N * divider;// automatically shifts left right depending on
value of divider
But this seems not to work.
math.pow() is again time consuming function. Can I use it? how much
faster is math.pow() function compared to if conditions?
Is there any way to avoid the if condition and do right shift and left
shift using operators depending on shiftby is +ve or -ve?
Bye
Sanny
Java Experts needed
http://www.GetClub.com/Experts.php
[Lots of coding jobs to choose]