There's a variable:
char segment = 0;
After 1 or with bit 15, segment = 1;
Just means this bit check already.
Question is how to cancel the mark of bit 15 (set back to 0)?
Use "~"?
There's a variable:
char segment = 0;
After 1 or with bit 15, segment = 1;
Just means this bit check already.
Question is how to cancel the mark of bit 15 (set back to 0)?
Use "~"?
Following program sets bit, clears bit and toggles bit
#include<stdio.h>
void main(void)
{
unsigned int byte;
unsigned int bit_position;
unsigned int tempbyte = 0x01;
//get the values of the byte and the bit positions
//set bit
byte = (byte | (tempbyte << bit_position));// set the bit at the position given by bit_position
//clear bit
byte = (byte & ~(tempbyte << bit_position));//clear the bit at the position given by bit_position
//toggle bits
byte = (byte ^ (tempbyte << bit_position));//toggle the bit at the position given by bit_position
}
To get rid of the MSB of an 8-bit character for example, you can AND with 0x7F
e.g. segment = segment & 0x7F;
To dynamically produce the mask, you can use bit shifting operations (i.e. the << operator).