Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All..

How can i find the address of last bit of an integer in C.


Thanks
Posted

A "bit" doesn't have an address - it is at a specific position within a byte / word / long word which will have an address.

And which bit do you mean is the "last bit"? The most significant? Or the least significant?

Just to make things worse, there is no standard for the address of the most or least significant byte of an integer - it depends on whether the target processor is "least-significant-first" - also known as "Little-endian" - or "most-significant-first" - also known as "Big-endian"

So sorry, we can't give you an answer that works in code: C systems can be either-endian, and a bit doesn't have an address, so can't be pointed at!
 
Share this answer
 
if you mean the 2^0 bit, you can't get the address of that ... you can get the address of each of the constituent bytes of that integer

However, that depends on the endian[^] format of the system AND the width of an integer in that system, 16, 32 or 64 bits[^]
 
Share this answer
 
If you mean the 2^0 bit, you can find its value with modulus 2 of the integer: INTEGER % 2.
 
Share this answer
 
Thanks to all

and how can i find the value of least significant bit of an integer.
 
Share this answer
 
Comments
Richard MacCutchan 15-Jun-12 9:16am    
value = integer & 1;
Sandeep Mewara 15-Jun-12 11:15am    
This is not an answer. Please use 'Have a Question or Comment' link to respond to an answer. It will notify answerer of your comment such that he can come back and reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900