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;

Recommended Answers

All 5 Replies

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;
}

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...?

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.