Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Verwendung von Funktionen
Maskieren.cpp
int setBit(int x, unsigned char position)
{
int mask = 1 << position;
return x | mask;
}
int clearBit(int x, unsigned char position)
{
int mask = 1 << position;
return x & ~mask;
}
int modifyBit(int x, unsigned char position, bool newState)
{
int mask = 1 << position;
int state = int(newState); // relies on true = 1 and false = 0
return (x & ~mask) | (-state & mask);
}
int flipBit(int x, unsigned char position)
{
int mask = 1 << position;
return x ^ mask;
}
bool isBitSet(int x, unsigned char position)
{
x >>= position;
return (x & 1) != 0;
}