1. WebAssembly
  2. Reference
  3. WebAssembly numerische Anweisungen
  4. ctz

Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

ctz: Wasm-Textanweisung

Die ctz-Anweisungen, kurz für count trailing zeros, werden verwendet, um die Anzahl der Nullen am Ende der binären Darstellung von Zahlen zu zählen.

Probieren Sie es aus

(module
 (func (export "trailing0") (param $num i32) (result i32)
 ;; load number onto the stack
 local.get $num
 ;; check how many trailing zeros and return the result
 i32.ctz
 )
)
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console }).then(
 (result) => {
 const trailing0 = result.instance.exports.trailing0;
 console.log(
 `Trailing zeros: ${trailing0(0b00000000_10000000_00000000_00000000)}`,
 );
 // Expected output: "Trailing zeros: 23"
 },
);

Syntax

wat
;; load a number onto the stack
i32.const 8388608 ;; 00000000_10000000_00000000_00000000
;; count trailing zeros
i32.ctz
;; the top item on the stack will now be 23
Anweisung Binärer Opcode
i32.ctz 0x68
i64.ctz 0x7a

Help improve MDN

Erfahren Sie, wie Sie beitragen können Diese Seite wurde automatisch aus dem Englischen übersetzt.

AltStyle によって変換されたページ (->オリジナル) /