英語版
このページの英語版を見る
core.bitop
このモジュールには、ビットレベルの操作のコレクションが含まれている。
License:
Authors:
Don Clugston, Sean Kelly, Walter Bright, Alex Rønne Petersen, Thomas Stuart Bockman
ソース core/bitop.d
- pure nothrow @nogc @safe int
bsf(uintv);
pure nothrow @nogc @safe intbsf(ulongv); - vのビットをビット0からスキャンし、最初にセットされたビットを探す。 を探す。Returns:最初にセットされたビットのビット番号を返す。 vが0の場合、戻り値は未定義である。Examples:
assert(bsf(0x21) == 0); assert(bsf(ulong.max << 39) == 39);
- pure nothrow @nogc @safe int
bsr(uintv);
pure nothrow @nogc @safe intbsr(ulongv); - vのビットを最上位ビットから最下位ビットまでスキャンする。 から最下位ビットまでを走査する。 最初にセットされたビットを探す。Returns:最初にセットされたビットのビット番号を返す。 vが0の場合、戻り値は未定義である。Examples:
assert(bsr(0x21) == 5); assert(bsr((ulong.max >> 15) - 1) == 48);
- pure nothrow @nogc @system int
bt(scope const size_t*p, size_tbitnum); - ビットをテストする。 (もはやイントリシクではない - コンパイラはボディ内のパターンを認識する) を認識する)。Examples:
size_t[2] array; array[0] = 2; array[1] = 0x100; assert(bt(array.ptr, 1)); assert(array[0] == 2); assert(array[1] == 0x100);
- pure nothrow @nogc @system int
btc(size_t*p, size_tbitnum); - ビットをテストし、補完する。
- pure nothrow @nogc @system int
btr(size_t*p, size_tbitnum); - ビットをテストし、リセット(0にする)する。
- pure nothrow @nogc @system int
bts(size_t*p, size_tbitnum); - ビットをテストし、設定する。Parameters:
size_t* psize_tsの配列へのNULLでないポインタ。 size_t bitnump[0]のビット0から始まるビット番号、 ビット番号。式のようにビットを指定する: p[index / (size_t.sizeof*8)] & (1 << (index & ((size_t.sizeof*8) - 1)))Returns:ビットがセットされていれば0以外の値、クリアされていれば0である。 である。Examples:size_t[2] array; array[0] = 2; array[1] = 0x100; assert(btc(array.ptr, 35) == 0); if (size_t.sizeof == 8) { assert(array[0] == 0x8_0000_0002); assert(array[1] == 0x100); } else { assert(array[0] == 2); assert(array[1] == 0x108); } assert(btc(array.ptr, 35)); assert(array[0] == 2); assert(array[1] == 0x100); assert(bts(array.ptr, 35) == 0); if (size_t.sizeof == 8) { assert(array[0] == 0x8_0000_0002); assert(array[1] == 0x100); } else { assert(array[0] == 2); assert(array[1] == 0x108); } assert(btr(array.ptr, 35)); assert(array[0] == 2); assert(array[1] == 0x100);
- struct
BitRange; - 設定されているビットの範囲。各要素は設定されているビット番号である。これは、ビットセットの各ビットをテストするよりも効率的である。 セットの各ビットをテストするよりも効率的である。ビットセットの最初のビットはビット0であることに注釈:。Examples:
import core.stdc.stdlib : malloc, free; import core.stdc.string : memset; // ビット配列を初期化する enum nBytes = (100 + BitRange.bitsPerWord - 1) / 8; size_t *bitArr = cast(size_t *)malloc(nBytes); scope(exit) free(bitArr); memset(bitArr, 0, nBytes); // いくつかのビットを設定する bts(bitArr, 48); bts(bitArr, 24); bts(bitArr, 95); bts(bitArr, 78); enum sum = 48 + 24 + 95 + 78; // 繰り返す size_t testSum; size_t nBits; foreach (b; BitRange(bitArr, 100)) { testSum += b; ++nBits; } assert(testSum == sum); assert(nBits == 4);
- enum ulong
bitsPerWord; - 各size_tのビット数
- pure nothrow @nogc @system this(const(size_t)*
bitarr, size_tnumBits); - BitRangeを構築する。Parameters:
const(size_t)* bitarr反復処理するビットの配列 size_t numBits与えられたビット配列内の有効なビットの総数 - pure nothrow @nogc @safe size_t
front();
const pure nothrow @nogc @safe boolempty();
pure nothrow @nogc @system voidpopFront(); - 範囲関数".
- pure nothrow @nogc @safe ushort
byteswap(ushortx); - 2バイトのushort内のバイトを入れ替える。Parameters:
ushort x値 Returns:xバイトを入れ替えたExamples:assert(byteswap(cast(ushort)0xF234) == 0x34F2); static ushort xx = 0xF234; assert(byteswap(xx) == 0x34F2);
- pure nothrow @nogc @safe uint
bswap(uintv); - つまり、バイト0はバイト2になる。 バイト1がバイト2になり、バイト2がバイト1になり、バイト3がバイト0になる。 がバイト0になる。Examples:
assert(bswap(0x01020304u) == 0x04030201u); static uint xx = 0x10203040u; assert(bswap(xx) == 0x40302010u);
- pure nothrow @nogc @safe ulong
bswap(ulongv); - つまり、バイト0はバイト6になる。 はバイト 7 に、バイト 1 はバイト 6 になる。 これは、組込み関数としてコンパイラに認識されることを意図している。Examples:
assert(bswap(0x01020304_05060708uL) == 0x08070605_04030201uL); static ulong xx = 0x10203040_50607080uL; assert(bswap(xx) == 0x80706050_40302010uL);
- nothrow @nogc @system ubyte
inp(uintport_address);
nothrow @nogc @system ushortinpw(uintport_address);
nothrow @nogc @system uintinpl(uintport_address); - port_address の I/O ポートを読み込む。
- nothrow @nogc @system ubyte
outp(uintport_address, ubytevalue);
nothrow @nogc @system ushortoutpw(uintport_address, ushortvalue);
nothrow @nogc @system uintoutpl(uintport_address, uintvalue); - port_addressのI/Oポートに値を書き込んで返す。
- pure nothrow @nogc @safe int
popcnt(uintx);
pure nothrow @nogc @safe intpopcnt(ulongx); - 整数のセットビット数を計算する
- pure nothrow @nogc @safe ushort
_popcnt(ushortx);
pure nothrow @nogc @safe int_popcnt(uintx);
pure nothrow @nogc @safe int_popcnt(ulongx); - X86 SSE4 POPCNT 命令を使用して、整数のセットビット数を計算する。 X86 SSE4 POPCNT 命令を使用する。 POPCNT は、すべての X86 CPU で使用できるわけではない。
- pure nothrow @nogc @safe uint
bitswap(uintx); - 32 ビット整数内のビットの順序を逆にする。
- pure nothrow @nogc @safe ulong
bitswap(ulongx); - 64 ビット整数のビットの順序を逆にする。
- pure T
rol(T)(const Tvalue, const uintcount)
if (__traits(isIntegral, T) && __traits(isUnsigned, T));
pure Tror(T)(const Tvalue, const uintcount)
if (__traits(isIntegral, T) && __traits(isUnsigned, T));
pure Trol(uint count, T)(const Tvalue)
if (__traits(isIntegral, T) && __traits(isUnsigned, T));
pure Tror(uint count, T)(const Tvalue)
if (__traits(isIntegral, T) && __traits(isUnsigned, T)); - ビットごとの回転
value左 (rol)または右回転(ror)で回転する。countビット単位で回転させる。Examples:ubyte a = 0b11110000U; ulong b = ~1UL; assert(rol(a, 1) == 0b11100001); assert(ror(a, 1) == 0b01111000); assert(rol(a, 3) == 0b10000111); assert(ror(a, 3) == 0b00011110); assert(rol(a, 0) == a); assert(ror(a, 0) == a); assert(rol(b, 63) == ~(1UL << 63)); assert(ror(b, 63) == ~2UL); assert(rol!3(a) == 0b10000111); assert(ror!3(a) == 0b00011110); enum c = rol(uint(1), 0); enum d = ror(uint(1), 0); assert(c == uint(1)); assert(d == uint(1));
Copyright © 1999-2025 by the D Language Foundation
DEEPL APIにより翻訳、ところどころ修正。
このページの最新版(英語)
このページの原文(英語)
翻訳時のdmdのバージョン: 2.108.0
サイト全体のドキュメントのdmdのバージョン: 2.109.1
最新のdmdのバージョン: 2.111.0 ダウンロード
翻訳日付:
HTML生成日時:
編集者: dokutoku