main Content

比尔

比特或

描述

例子

C= bitor(一种,,,,b返回位或一种andb

例子

C= bitor(一种,,,,b,,,,假设assumes that一种andb假设

objout= bitor(NetObj1,,,,NetObj2返回位或the .NET enumeration objectsNetObj1andNetObj2

例子

全部收缩

为逻辑或操作创建真实表。

a = uint8([0 1; 0 1]);b = uint8([0 0; 1 1]);ttable = bitor(a,b)
TTable =2x2 UINT8矩阵0 1 1 1

比尔返回1如果任何位输入为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)。

因此,位或-5(-5)(11111011)和6(00000110)is -1 (11111111)。

a = -5;bitget(a,8:-1:1,'int8'
ans =1×8111110 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 1

Use比尔andbitshift将四个8位字节打包成他们组成的32位整数。

Create four bytes of data. Specify the data with hexadecimal literals, using the-U32suffix to specify that the data should be stored asUINT32。每个字节包含8位价值的数据。

byte4 = 0x87u32; byte3 = 0x65u32; byte2 = 0x43u32; byte1 = 0x21u32;

首先将第一个字节添加为32位未签名整数的前8位。

包装= byte1;

接下来,将其他三个字节打包到包装, 使用bitshiftto shift the bytes to the proper locations, and比尔复制位。

packednum = bitor(packednum,bitshift(byte2,8));packednum = bitor(packednum,bitshift(byte3,8*2));packednum = bitor(packednum,bitshift(byte4,8*3));

查看包装的32位整数。

format十六进制包装
包装=UINT3287654321

输入参数

全部收缩

输入值,指定为标量,向量,矩阵或多维数组。输入一种andb必须是相同的大小或具有兼容的尺寸(例如,一种是一个m-by-n矩阵和b是一个标量或1-by-n行矢量)。有关更多信息,请参阅兼容阵列大小用于基本操作一种andb也必须是相同的数据类型,除非一个数据类型是标量double。

  • 如果一种andb是双阵列,假设未指定,然后是matlab®treats一种andbas unsigned 64-bit integers.

  • 如果假设is specified, then all elements in一种andb必须在范围内具有整数值假设

数据类型:双倍的|逻辑|int8|int16|int32|INT64|UINT8|UINT16|UINT32|Uint64

假定的数据类型一种andb,指定为'uint64',,,,'uint32',,,,'uint16',,,,'uint8',,,,'int64',,,,'int32',,,,'int16', 或者'int8'

  • 如果一种andb是双阵列,然后假设can specify any valid integer type, but defaults to'uint64'

  • 如果一种andb是整数类型数组,然后假设必须指定相同的整数类型。

数据类型:char|细绳

输入值,指定为.NET枚举对象。您必须运行Windows的版本®to use .NET enumeration objects as input arguments.

比尔是一种由.NET枚举创建的MATLAB枚举对象的实例方法。

输出参数

全部收缩

比特或result, returned as an array.C与数据类型相同一种andb

  • 如果是一种orb是标量double,另一个是整数类型,然后Cis the integer type.

位或结果,作为.NET枚举对象返回。

扩展功能

C/C ++代码生成
Generate C and C++ code using MATLAB® Coder™.

GPU代码生成
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

HDL代码生成
Generate Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™.

版本历史记录

Introduced before R2006a