bitor
Bit-wise OR
Description
假设C
= bitor(a,b
,assumedtype
)A
和B
are ofassumedtype
.
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 matrix0 1 1 1
bitor
returns 1 if either bit-wise input is 1.
负值
MATLAB®使用两个补充编码负整数。例如,要查找两者的补充表示-5,您采用了数字的正版本的位模式(00000101
),交换每个位(11111010
),然后在结果中加1(11111011
).
Therefore, the bit-wise OR of -5 (11111011
) and 6 (00000110
)是-1(11111111
).
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 = bitor(a,b,'int8')
c = -1
bitget(c,8:-1:1,'int8')
ans =1×81 1 1 1 1 1 1 1
Combine Bytes into 32-bit Unsigned Integer
Usebitor
和bitshift
to pack four 8-bit bytes into the 32-bit integer they make up.
创建四个字节数据。使用十六进制文字指定数据,使用-u32
后缀以指定数据应存储为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 intopackedNum
, usingbitshift
将字节转移到适当的位置,并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.
格式hexpackedNum
packednum =uint3287654321
Input Arguments
a,b
—Input values
标量|向量|矩阵|多维阵列
Input values, specified as scalars, vectors, matrices, or multidimensional arrays. InputsA
和B
must either be the same size or have sizes that are compatible (for example,A
is anM
-经过-N
matrix andB
is a scalar or1
-经过-N
row vector). For more information, seeCompatible Array Sizes for Basic Operations.A
和B
also must be the same data type unless one is a scalar double.
If
A
和B
双阵列,assumedtype
is not specified, then MATLAB®零食A
和B
作为未签名的64位整数。If
assumedtype
指定,然后在A
和B
must have integer values within the range ofassumedtype
.
Data Types:double
|logical
|int8
|INT16
|INT32
|int64
|uint8
|uint16
|uint32
|uint64
assumedtype
—Assumed data type ofinteg1
和integ2
'uint64'
|'uint32'
|'uint16'
|“uint8'
|'int64'
|'int32'
|'int16'
|'int8'
Assumed data type ofA
和B
, specified as'uint64'
,'uint32'
,'uint16'
,“uint8'
,'int64'
,'int32'
,'int16'
, or'int8'
.
If
A
和B
are double arrays, thenassumedtype
可以指定任何有效的整数类型,但默认为'uint64'
.If
A
和B
are integer type arrays, thenassumedtype
must specify that same integer type.
Data Types:char
|string
netobj1
,netobj2
—Input values
.NET枚举对象
Input values, specified as .NET enumeration objects. You must be running a version of Windows®将.NET枚举对象用作输入参数。
bitor
is an instance method for MATLAB enumeration objects created from a .NET enumeration.
Output Arguments
C
— Bit-wise OR result
大批
位或结果,作为数组返回。C
is the same data type asA
和B
.
If either
A
或者B
is a scalar double, and the other is an integer type, thenC
是整数类型。
objout
— Bit-wise OR result
.NET enumeration object
Bit-wise OR result, returned as a .NET enumeration objects.
Extended Capabilities
C/C++ Code Generation
使用MATLAB®CODER™生成C和C ++代码。
GPU Code Generation
使用GPU CODER™为NVIDIA®GPU生成CUDA®代码。
HDL Code Generation
使用HDL Coder™生成用于FPGA和ASIC设计的Verilog和VHDL代码。
Thread-Based Environment
Run code in the background using MATLAB®背景池
或者accelerate code with Parallel Computing Toolbox™ThreadPool
.
This function fully supports thread-based environments. For more information, seeRun MATLAB Functions in Thread-Based Environment.
GPU Arrays
使用并行计算工具箱™在图形处理单元(GPU)上运行加速代码。
Usage notes and limitations:
两个输入都可以是无符号整数数组,也可以是一个输入可以是无符号整数数组,而另一个输入可以是标量double。
不支持64位整数。万博1manbetx
The
assumedtype
argument is not supported.
For more information, seeRun 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运行具有分布式数组的MATLAB功能(Parallel Computing Toolbox).
Version History
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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:.
您还可以从以下列表中选择一个网站:
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éricaLatina(Español)
- Canada(English)
- United States(English)
欧洲
- Belgium(English)
- 丹麦(English)
- Deutschland(德意志)
- España(Español)
- Finland(English)
- 法国(Français)
- 爱尔兰(English)
- 意大利(Italiano)
- Luxembourg(English)
- Netherlands(English)
- 挪威(English)
- Österreich(德意志)
- Portugal(English)
- Sweden(English)
- 瑞士
- United Kingdom(English)