bitxor - Bit-wise XOR - MATLAB (original) (raw)

Syntax

Description

[C](#bth4gv%5F-C) = bitxor([A,B](#bth4gv%5F-AB)) returns the bit-wise XOR of A and B.

example

[C](#bth4gv%5F-C) = bitxor([A,B](#bth4gv%5F-AB),[assumedtype](#bth4gv%5F-assumedtype)) assumes that A and B are of assumedtype.

example

[objout](#bth4gv%5F-objout) = bitxor([netobj1](#bth4gv%5F-netobj1),[netobj2](#bth4gv%5F-netobj1)) returns the bit-wise XOR of the .NET enumeration objects netobj1 and netobj2.

Examples

collapse all

Truth Table

Create a truth table for the logical XOR operation.

A = uint8([0 1; 0 1]); B = uint8([0 0; 1 1]); TTable = bitxor(A, B)

TTable = 2x2 uint8 matrix

0 1 1 0

bitxor returns 0 if both bit-wise inputs are equal.

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 XOR of -5 (11111011) and 6 (00000110) is -3 (11111101).

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

ans = 1×8

 1     1     1     1     1     1     0     1

Input Arguments

collapse all

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.

Data Types: double | logical | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

assumedtype — Assumed data type of A and B

'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'.

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.

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

Output Arguments

collapse all

C — Bit-wise XOR result

array

Bit-wise XOR result, returned as an array. C is the same data type as A and B.

objout — Bit-wise XOR result

.NET enumeration object

Bit-wise XOR 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 bitxor function supports GPU array input with these usage notes and limitations:

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:

For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).

Version History

Introduced before R2006a