Die statische Atomics
.xor()
Methode berechnet eine bitweises XOR mit einem gegebenen Wert auf einem Wert an einer gegebenen Position im Array und gibt den alten Wert an der Position zurück. Die atomare Operation garantiert, dass kein anderer Schreibprozess während der Operation durchgeführt wird.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Syntax
Atomics.and(typedArray, index, value)
Parameter
typedArray
- Ein geteiltes getrypted Integer Array. Eines von
Int8Array
,Uint8Array
,Int16Array
,Uint16Array
,Int32Array
oderUint32Array
. index
- Die Position in
typedArray
, mit der das bitweise XOR berechnet wird. value
- Die Zahl, mit der das bitweise XOR berechnet wird.
Rückgabewert
Der alte Wert an der gegebenen Position (typedArray[index]
).
Exceptions
- Erzeugt einen
TypeError
, wenntypedArray
nicht von einem erlaubten Integer Typ ist. - Erzeugt eine
TypeError
, wenntypedArray
kein geteilter Arraytyp ist. - Erzeugt ein
RangeError
, wenn derindex
nicht in den Grenzen vontypedArray
ist.
Beschreibung
Die bitweise XOR Operation ergibt nur 1, wenn genau ein Werte, a
oder b
, 1 ist. Die Wahrheitstabelle für die XOR Operation ist:
a |
b |
a & b |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Zum Beispiel resultiert ein bitweises XOR auf 5 & 1
in 0100
, was im Dezimalsystem 4 ist.
5 0101 1 0001 ---- 4 0100
Beispiele
var sab = new SharedArrayBuffer(1024);
var ta = new Uint8Array(sab);
ta[0] = 5;
Atomics.xor(ta, 0, 1); // returns 5, the old value
Atomics.load(ta, 0); // 4
Spezifikationen
Spezifikation | Status | Kommentar |
---|---|---|
ECMAScript (ECMA-262) Die Definition von 'Atomics.xor' in dieser Spezifikation. |
Lebender Standard | Initiale Definition in ES2017. |
Browserkompatibilität
BCD tables only load in the browser