Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Français - Português - 日本語
Справка Scilab >> Основные функции > Побитовые операции > bitxor

bitxor

bitwise logical XOR between element-wise integers of 2 arrays

Syntax

w = bitxor(u, v)

Parameters

u, v, w

scalars, vectors, matrices or hypermatrices of null or positive integers encoded as decimal or integer numbers of any signed or unsigned inttype.

Sparse-encoded matrices are not accepted.

If u and v have the same type and inttype, this one is the working one. Otherwise,

  • if u or v is decimal-encoded, the working inttype is 0 (real decimal), even if the other operand is int64- or uint64-encoded.
  • if u and v are both encoded integers, the working inttype is the widest of both: int8 < uint8 < int16 < uint16 < int32 < uint32 < int64 < uint64.

The result w gets the type of the working encoding.

u and v are processed element-wise:

  • If u is a single value (scalar) and v is a vector, matrix or hypermatrix, u is priorly expanded as u*ones(v) in order to operate u with every v component.
  • Conversely, v is priorly expanded as v*ones(u) if it is a single value.
  • If neither u nor v are scalars, they must have the same sizes.

The result w gets the sizes of u or/and v arrays.

Description

For each pair of components u(i) and v(i), bitxor(u, v) computes and returns in w(i) the bitwise XOR eXclusive-OR conjunction of u(i) and v(i) bits.
With encoded integers, bitxor(u,v) is equivalent to (u | v) & ~(u & v). However, both | and & operators demand that u and v have the same inttype, while bitxor(..) accepts mixed operands.
For any decimal integer u greater than 2^52, only its bits from log2(u) down to log2(u)-52 are encoded and can be actually taken into account. Lower bits are not stored and are then ignored.

Examples

bitxor(25, 33)
dec2bin([25 33 56]')  // binary representations
--> bitxor(25, 33)
 ans  =
   56.

--> dec2bin([25 33 56]'))
 ans  =
!011001  !
!100001  !
!111000  !

// Between 2 simple rows with zeros and ones
u = [0 1 0 1];
v = [0 0 1 1];
bitxor(u, v)  // [0 1 1 0] expected

// Encoded integers such as int8 are accepted:
u = int8([0 1 0 1]);
v = int8([0 0 1 1]);
bitxor(u, v)

// Operands of mixed types are accepted.
// The type of the result is decimal if a decimal operand is involved,
// or the widest integer one otherwise:
u = [0 1 0 1];
v = [0 0 1 1];
z = bitxor(u, int64(v));          type(z)       // 1 : decimal representation
z = bitxor(uint8(u), int8(v));    typeof(z)     // uint8
z = bitxor(uint8(u), int32(v));   typeof(z)     // int32

// Usage with 2 matrices
u = [  1    2    4   8
      25   33   25  33 ];
v = [  2  2+4  4+8  16
      33   25   56  56 ];
bitxor(u, v)      //  [ 3 4 8 24 ;  56 56 33 25 ]   expected

// Usage with a distributed scalar:
bitxor([1 2 4 8 9 10 12], 8)  // == bitxor([1 2 4 8 9 10 12], [8 8 8 8 8 8 8])
bitxor(4, [1 2 4 8 9 10 12])  // == bitxor([4 4 4 4 4 4 4], [1 2 4 8 9 10 12])

// Examples with big decimal integers:

u = sum(2 .^(600+[0 3 9 20 45]))        // ~ 1.46D+194
bitxor(u, 2^630) == u+2^630  // true: XOR sets to 1 the missing bit #630 of u, so adds it
bitxor(u, 2^645) == u-2^645  // true: XOR sets to 0 the existing bit #645 of u, so removes it
bitxor(u, 2^601) == u        // false: The bit #601 is 0 in u. XOR changes it.
//
n = fix(log2(u))           // 645 == Index of the heaviest bit of u
bitxor(u, 2^(n-52)) == u   // false: The lightest bit of u was at 0 => This changes it
bitxor(u, 2^(n-53)) == u   // true: Addressing bits below the lightest one doesn't change u

See also

  • | — Binary OR between integers. Logical OR over/between booleans and numbers
  • or — logical OR over the elements of a boolean or numerical array
  • bitor — bitwise logical OR between element-wise integers of 2 arrays
  • bitand — bitwise logical AND between element-wise integers of 2 arrays
  • dec2bin — преобразование из десятичной системы счисления в двоичную

History

ВерсияОписание
6.0
  • Extension to positive signed encoded integers
  • Extension to new int64 and uint64 inttypes
  • Operands of mixed types or inttypes are now accepted.
  • bitxor(scalar, array) and bitxor(array, scalar) are now supported.
  • Extension to decimal numbers greater than 2^32 and even than 2^52, up to 1.80D+308 (== number_properties("huge")), for the 52 heaviest encoded bits of their unsigned mantissa.
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 14 15:13:21 CET 2017