主要内容

bitor

Bit-wise OR

Description

example

C= bitor(a,b)returns the bit-wise OR ofAB.

example

C= bitor(a,b,assumedtype)假设ABare ofassumedtype.

objout= bitor(netobj1,netobj2)返回位或.NET枚举对象netobj1netobj2.

Examples

collapse all

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

bitorreturns 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

Usebitorbitshiftto 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将字节转移到适当的位置,并bitorto 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

collapse all

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

  • IfAB双阵列,assumedtypeis not specified, then MATLAB®零食AB作为未签名的64位整数。

  • Ifassumedtype指定,然后在ABmust have integer values within the range ofassumedtype.

Data Types:double|logical|int8|INT16|INT32|int64|uint8|uint16|uint32|uint64

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

  • IfABare double arrays, thenassumedtype可以指定任何有效的整数类型,但默认为'uint64'.

  • IfABare 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®将.NET枚举对象用作输入参数。

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

Output Arguments

collapse all

位或结果,作为数组返回。Cis the same data type asAB.

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

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代码。

Version History

在R2006a之前引入