# bitand

## Syntax

• `intout = bitand(integ1,integ2)` example
• `intout = bitand(integ1,integ2,assumedtype)` example
• `objout = bitand(netobj1,netobj2)`

## Description

example

````intout = bitand(integ1,integ2)` returns the bit-wise AND of values `integ1` and `integ2`. ```

example

````intout = bitand(integ1,integ2,assumedtype)` assumes that `integ1` and `integ2` are of `assumedtype`. ```
````objout = bitand(netobj1,netobj2)` returns the bit-wise AND of the .NET enumeration objects `netobj1` and `netobj2`.```

## Examples

collapse all

### Truth Table

Create a truth table for the logical AND operation.

```A = uint8([0 1; 0 1]); B = uint8([0 0; 1 1]); TTable = bitand(A, B)```
```TTable = 0 0 0 1 ```

`bitand` returns 1 only if both bit-wise inputs are 1.

### Negative Values

Explore how `bitand` handles negative values

MATLAB® encodes signed integers using two's complement. Thus, the bit-wise AND of `—`5 (11111011) and 6 (00000110) is 2 (00000010).

```C = -5; D = 6; bitand(C,D,'int8')```
```ans = 2```

## Input Arguments

collapse all

### `integ1`, `integ2` — Input valuessigned integer arrays | unsigned integer arrays | double arrays

Input values, specified as signed integer arrays, unsigned integer arrays, or double arrays. `integ1` and `integ2` must be the same data type, or one must be a scalar double value.

• If `integ1` and `integ2` are double arrays, and `assumedtype` is not specified, then MATLAB treats `integ1` and `integ2` as unsigned 64-bit integers.

• If `assumedtype` is specified, then all elements in `integ1` and `integ2` must have integer values within the range of `assumedtype`.

Data Types: `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

### `assumedtype` — Assumed data type of `integ1` and `integ2``'uint64'` | `'uint32'` | `'uint16'` | `'uint8'` | `'int64'` | `'int32'` | `'int16'` | `'int8'`

Assumed data type of `integ1` and `integ2`, specified as `'uint64'`, `'uint32'`, `'uint16'`, `'uint8'`, `'int64'`, `'int32'`, `'int16'`, or `'int8'`.

• If `integ1` and `integ2` are double arrays, then `assumedtype` can specify any valid integer type, but defaults to `'uint64'`.

• If `integ1` and `integ2` are integer type arrays, then `assumedtype` must specify that same integer type.

Data Types: `char`

### `netobj1`, `netobj2` — Input values.NET enumeration objects

Input values, specified as .NET enumeration objects. You must be running a version of Windows® to use .NET enumeration objects as input arguments.

`bitand` is an instance method for MATLAB enumeration objects created from a .NET enumeration.

## Output Arguments

collapse all

### `intout` — Bit-wise AND resultsigned integer array | unsigned integer array | double array

Bit-wise AND result, returned as a signed integer array, unsigned integer array, or double array. `intout` is the same data type and size as `integ1` and `integ2`.

• If either `integ1` or `integ2` is a scalar double, and the other is a non-double integer type, `intout` is the non-double integer type.

### `objout` — Bit-wise AND result.NET enumeration object

Bit-wise AND result, returned as a .NET enumeration objects.