Main Content

bitand

Bit-wise AND

Description

example

C= bitand(A,B)returns the bit-wise AND ofAandB.

example

C= bitand(A,B,assumedtype)assumes thatAandBare ofassumedtype.

objout= bitand(netobj1,netobj2)returns the bit-wise AND of the .NET enumeration objectsnetobj1andnetobj2.

Examples

collapse all

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 =2x2 uint8 matrix0 0 0 1

bitandreturns 1 only if both bit-wise inputs are 1.

MATLAB® encodes negative integers using two's complement. For example, to find the two's complement representation of -5, you take the bit pattern of the positive version of the number (00000101), swap each bit (11111010), and then add 1 to the result (11111011).

Therefore, the bit-wise AND of -5 (11111011) and 6 (00000110) is 2 (00000010).

a = -5; bitget(a,8:-1:1,'int8')
ans =1×81 1 1 1 1 0 1 1
b = 6; bitget(b,8:-1:1,'int8')
ans =1×80 0 0 0 0 1 1 0
c = bitand(a,b,'int8')
c = 2
bitget(c,8:-1:1,'int8')
ans =1×80 0 0 0 0 0 1 0

Input Arguments

collapse all

Input values, specified as scalars, vectors, matrices, or multidimensional arrays. InputsAandBmust either be the same size or have sizes that are compatible (for example,Ais anM-by-Nmatrix andBis a scalar or1-by-Nrow vector). For more information, seeCompatible Array Sizes for Basic Operations.AandBalso must be the same data type unless one is a scalar double.

  • IfAandB双阵列,assumedtypeis not specified, then MATLAB®treatsAandBas unsigned 64-bit integers.

  • Ifassumedtypeis specified, then all elements inAandBmust have integer values within the range ofassumedtype.

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

Assumed data type ofAandB, specified as'uint64','uint32','uint16',“uint8','int64','int32','int16', or'int8'.

  • IfAandBare double arrays, thenassumedtypecan specify any valid integer type, but defaults to'uint64'.

  • IfAandBare integer type arrays, thenassumedtypemust specify that same integer type.

Data Types:char|string

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

bitandis an instance method for MATLAB enumeration objects created from a .NET enumeration.

Output Arguments

collapse all

Bit-wise AND result, returned as an array.Cis the same data type asAandB.

  • If eitherAorBis a scalar double, and the other is an integer type, thenC是整数类型。

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

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

HDL Code Generation
Generate Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™.

Version History

Introduced before R2006a