Baseline Widely available
Die Atomics.and()
statische Methode berechnet ein bitweises UND mit einem gegebenen Wert an einer bestimmten Position im Array und gibt den alten Wert an dieser Position zurück. Diese atomare Operation garantiert, dass kein anderes Schreiben stattfindet, bis der geänderte Wert zurückgeschrieben wird.
// Create a SharedArrayBuffer with a size in bytes
const buffer = new SharedArrayBuffer(16);
const uint8 = new Uint8Array(buffer);
uint8[0] = 7;
// 7 (0111) AND 2 (0010) = 2 (0010)
console.log(Atomics.and(uint8, 0, 2));
// Expected output: 7
console.log(Atomics.load(uint8, 0));
// Expected output: 2
Syntax
Atomics.and(typedArray, index, value)
Parameter
typedArray
Ein Integer-typisiertes Array. Eines von Int8Array
, Uint8Array
, Int16Array
, Uint16Array
, Int32Array
, Uint32Array
, BigInt64Array
oder BigUint64Array
.
index
Die Position im typedArray
, an der das bitweise UND berechnet werden soll.
value
Die Zahl, mit der das bitweise UND berechnet werden soll.
Der alte Wert an der angegebenen Position (typedArray[index]
).
TypeError
Wird ausgelöst, wenn typedArray
nicht einer der erlaubten Integer-Typen ist.
RangeError
Wird ausgelöst, wenn index
auÃerhalb des Bereichs im typedArray
liegt.
Die bitweise UND-Operation ergibt nur dann 1, wenn sowohl a
als auch b
1 sind. Die Wahrheitstabelle für die UND-Operation ist:
a
b
a & b
0 0 0 0 1 0 1 0 0 1 1 1
Ein Beispiel: Ein bitweises UND von 5 & 1
ergibt 0001
, was im Dezimalsystem 1 ist.
5 0101 1 0001 ---- 1 0001Beispiele Verwendung von and()
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);
ta[0] = 5;
Atomics.and(ta, 0, 1); // returns 5, the old value
Atomics.load(ta, 0); // 1
Spezifikationen Browser-Kompatibilität Siehe auch
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4