i want to get the 6th bit of 48th character of z_Data
{
char c = pPkt->z_Data[47]; // this z_Data is a char buffer
std::cout<<(c>>3)&1<<std::endl;
std::cout<<(c>>4)&1<<std::endl;
std::cout<<(c>>5)&1<<std::endl;
}
<<
has a higher precedence than that of &
, so you need:
std::cout << ((c >> 3) & 1) << std::endl;
std::cout << ((c >> 4) & 1) << std::endl;
std::cout << ((c >> 5) & 1) << std::endl;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.