Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 bits off a word

Status
Not open for further replies.

japhy

Programmer
Sep 27, 2004
12
US
Hi, i'm fairly new to working with binary files

How can i strip the last TWO bits off a 32 bit word?

i was doing something like

void First12bits(unsigned short* memblock)
{
*memblock = (*memblock & 0x0FFF);
}

to get the first 12 bits previously,

Thanks for the help
Dan
 
Code:
void RemoveLowest2Bits(unsigned short& memblock)
{
    memblock &= ~3;
}

/Per
[sub]
www.perfnurt.se[/sub]
 
Or slightly more affected (and precious;):
Code:
template<class T> inline T& strip2last(T& t) 
{ 
  t &= ~3; return t; 
}
 
>How can i strip the last TWO bits off a 32 bit word?

short (signed or not) is 16 bits.

But anyway...

/Per
[sub]
www.perfnurt.se[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top