bitor
Bit-wise OR
Description
assumes
that C
= bitor(A,B
,assumedtype
)A
and B
are of assumedtype
.
Examples
Truth Table
Create a truth table for the logical OR operation.
A = uint8([0 1; 0 1]); B = uint8([0 0; 1 1]); TTable = bitor(A, B)
TTable = 2x2 uint8 matrix
0 1
1 1
bitor
returns 1 if either bit-wise input is 1.
Negative Values
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 OR of -5 (11111011
) and 6 (00000110
) is -1 (11111111
).
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 = bitor(a,b,'int8')
c = -1
bitget(c,8:-1:1,'int8')
ans = 1×8
1 1 1 1 1 1 1 1
Combine Bytes into 32-bit Unsigned Integer
Use bitor
and bitshift
to pack four 8-bit bytes into the 32-bit integer they make up.
Create four bytes of data. Specify the data with hexadecimal literals, using the -u32
suffix to specify that the data should be stored as uint32
. Each byte contains 8 bits worth of data.
byte4 = 0x87u32; byte3 = 0x65u32; byte2 = 0x43u32; byte1 = 0x21u32;
Start by adding the first byte as the first 8 bits of a 32-bit unsigned integer.
packedNum = byte1;
Next, pack the other three bytes into packedNum
, using bitshift
to shift the bytes to the proper locations, and bitor
to copy the bits over.
packedNum = bitor(packedNum,bitshift(byte2,8)); packedNum = bitor(packedNum,bitshift(byte3,8*2)); packedNum = bitor(packedNum,bitshift(byte4,8*3));
View the packed 32-bit integer.
format hex
packedNum
packedNum = uint32
87654321
Input Arguments
A,B
— Input values
scalars | vectors | matrices | multidimensional arrays
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
A
andB
are double arrays, andassumedtype
is not specified, then MATLAB® treatsA
andB
as unsigned 64-bit integers.If
assumedtype
is specified, then all elements inA
andB
must have integer values within the range ofassumedtype
.
Data Types: double
| logical
| 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 A
and B
,
specified as 'uint64'
, 'uint32'
, 'uint16'
, 'uint8'
, 'int64'
, 'int32'
, 'int16'
,
or 'int8'
.
If
A
andB
are double arrays, thenassumedtype
can specify any valid integer type, but defaults to'uint64'
.If
A
andB
are integer type arrays, thenassumedtype
must specify that same integer type.
Data Types: char
| string
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.
bitor
is an instance method for MATLAB enumeration
objects created from a .NET enumeration.
Output Arguments
C
— Bit-wise OR result
array
Bit-wise OR result, returned as an array. C
is
the same data type as A
and B
.
If either
A
orB
is a scalar double, and the other is an integer type, thenC
is the integer type.
objout
— Bit-wise OR result
.NET enumeration object
Bit-wise OR 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™.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
The bitor
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
assumedtype
argument is not supported.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
Usage notes and limitations:
The
assumedtype
argument 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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)