0

An unsigned integer is of 2 bits.
What i wnat to do is to shift an int a right one time and at the same time obtain the A(15) bit in some variable how can i do that?

i know this will perform a right shift on int a and store the result int b.

int a;
int b=a<<1;
3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by praky
0

I'm not really sure what you mean...Is it something like below?

#include <iostream>

int main(int argc, char**argv)
{
	unsigned int i = 0;
	unsigned int x = 1;
	int size = sizeof(unsigned int);
	size *= 8;

	std::cout<<"ans->"<<x<<std::endl;

	for (i = 0; i < size; ++i)
		std::cout<<"ans->"<<(x <<= 1)<<std::endl;

	return 0;
}
0

What i mean is that if i do a right shift, where does the LSB goes?
can i save it while doing so, or is it lost for ever and ever...?

0

well in assembly language it is very easy to store bits. You can easily write a routine for this purpose, look for the topic left shift and right shift

0

What i mean is that if i do a right shift, where does the LSB goes?
can i save it while doing so, or is it lost for ever and ever...?

Where does it go? Its truncated. Can you save it? Yes you can by masking out the value before you shift.

Edited by gerard4143: n/a

0

Ok thanks. Thats what i wanted to know whether it should be masked and stored or if there was an easier way around.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.