# Bit Manipulation

## Description

Bitwise operations.

## Macros

#define SL_SET_BIT(val, mask)   ((val) = ((val) | (mask)))
Set specified bit(s) in a value.

#define SL_CLEAR_BIT(val, mask)   ((val) = ((val) & (~(mask))))
Clear specified bit(s) in a value.

#define SL_IS_BIT_SET(val, mask)   (((((val) & (mask)) == (mask)) && ((mask) != 0u)) ? (true) : (false))
Determine whether the specified bit(s) in a value are set.

#define SL_IS_BIT_CLEAR(val, mask)   (((((val) & (mask)) == 0u) && ((mask) != 0u)) ? (true) : (false))
Determine whether the specified bit(s) in a value are clear.

#define SL_IS_ANY_BIT_SET(val, mask)   ((((val) & (mask)) == 0u) ? (false) : (true))
Determine whether any specified bit(s) in a value are set.

#define SL_IS_ANY_BIT_CLEAR(val, mask)   ((((val) & (mask)) == (mask)) ? (false) : (true))
Determine whether any specified bit(s) in a value are clear.

## ◆ SL_SET_BIT

 #define SL_SET_BIT ( `val, ` `mask ` ) ((val) = ((val) | (mask)))

Set specified bit(s) in a value.

```                                          SL_SET_BIT()
```
Parameters
 `val` Value to modify by setting specified bit(s). `mask` Mask of bits to set.
Returns
Modified value with specified bit(s) set.
Note
'val' & 'mask' SHOULD be unsigned integers.

## ◆ SL_CLEAR_BIT

 #define SL_CLEAR_BIT ( `val, ` `mask ` ) ((val) = ((val) & (~(mask))))

Clear specified bit(s) in a value.

```                                          SL_CLEAR_BIT()
```
Parameters
 `val` Value to modify by clearing specified bit(s). `mask` Mask of bits to clear.
Returns
Modified value with specified bit(s) clear.
Note
'val' & 'mask' SHOULD be unsigned integers.
'mask' SHOULD be cast with the same data type than 'val'.

## ◆ SL_IS_BIT_SET

 #define SL_IS_BIT_SET ( `val, ` `mask ` ) (((((val) & (mask)) == (mask)) && ((mask) != 0u)) ? (true) : (false))

Determine whether the specified bit(s) in a value are set.

```                                          SL_IS_BIT_SET()
```
Parameters
 `val` Value to check for specified bit(s) set. `mask` Mask of bits to check if set.
Returns
true, if ALL specified bit(s) are set in value.
```      false, if ALL specified bit(s) are NOT set in value.
```
Note
'val' & 'mask' SHOULD be unsigned integers.
NULL 'mask' allowed; returns 'false' since NO mask bits specified.

## ◆ SL_IS_BIT_CLEAR

 #define SL_IS_BIT_CLEAR ( `val, ` `mask ` ) (((((val) & (mask)) == 0u) && ((mask) != 0u)) ? (true) : (false))

Determine whether the specified bit(s) in a value are clear.

```                                          SL_IS_BIT_CLEAR()
```
Parameters
 `val` Value to check for specified bit(s) clear. `mask` Mask of bits to check if clear.
Returns
true, if ALL specified bit(s) are clear in value.
```      false, if ALL specified bit(s) are NOT clear in value.
```
Note
val' & 'mask' SHOULD be unsigned integers.
NULL 'mask' allowed; returns 'false' since NO mask bits specified.

## ◆ SL_IS_ANY_BIT_SET

 #define SL_IS_ANY_BIT_SET ( `val, ` `mask ` ) ((((val) & (mask)) == 0u) ? (false) : (true))

Determine whether any specified bit(s) in a value are set.

```                                      SL_IS_ANY_BIT_SET()
```
Parameters
 `val` Value to check for specified bit(s) set. `mask` Mask of bits to check if set (see Note #2).
Returns
true, if ANY specified bit(s) are set in value.
```      false, if ALL specified bit(s) are NOT set in value.
```
Note
'val' & 'mask' SHOULD be unsigned integers.
NULL 'mask' allowed; returns 'false' since NO mask bits specified.

## ◆ SL_IS_ANY_BIT_CLEAR

 #define SL_IS_ANY_BIT_CLEAR ( `val, ` `mask ` ) ((((val) & (mask)) == (mask)) ? (false) : (true))

Determine whether any specified bit(s) in a value are clear.

```                                      SL_IS_ANY_BIT_CLEAR()
```
Parameters
 `val` Value to check for specified bit(s) clear. `mask` Mask of bits to check if clear (see Note #2).
Returns
true, if ANY specified bit(s) are clear in value.
```      false,  if ALL specified bit(s) are NOT clear in value.
```
Note
'val' & 'mask' SHOULD be unsigned integers.
NULL 'mask' allowed; returns 'false' since NO mask bits specified.