bitand
Bit-wise AND
Description
Examples
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 = 2×2 uint8 matrix
0 0
0 1
bitand returns 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×8
1 1 1 1 1 0 1 1
b = 6;
bitget(b,8:-1:1,'int8')ans = 1×8
0 0 0 0 0 1 1 0
c = bitand(a,b,'int8')c = 2
bitget(c,8:-1:1,'int8')ans = 1×8
0 0 0 0 0 0 1 0
Input Arguments
Input values, specified as scalars, vectors, matrices, or multidimensional
arrays. Inputs A and B must
either be the same size or have sizes that are compatible (for example, A is
an M-by-N matrix and B is
a scalar or 1-by-N row vector).
For more information, see Compatible Array Sizes for Basic Operations. A and B also
must be the same data type unless one is a scalar double.
If
AandBare double arrays, andassumedtypeis not specified, then MATLAB® treatsAandBas unsigned 64-bit integers.If
assumedtypeis 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 of A and B,
specified as 'uint64', 'uint32', 'uint16', 'uint8', 'int64', 'int32', 'int16',
or 'int8'.
If
AandBare double arrays, thenassumedtypecan specify any valid integer type, but defaults to'uint64'.If
AandBare 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.
bitand is an instance method for MATLAB enumeration
objects created from a .NET enumeration.
Output Arguments
Bit-wise AND result, returned as an array. C is
the same data type as A and B.
If either
AorBis a scalar double, and the other is an integer type, thenCis the integer type.
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 VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
The bitand function
supports GPU array input with these usage notes and limitations:
Both inputs can be unsigned integer arrays, or one input can be an unsigned integer array and the other input can be a scalar double.
64-bit integers are not supported.
The
assumedtypeargument is not supported.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Usage notes and limitations:
The
assumedtypeargument is not supported.
For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)