View source code Display the source code in std/bitmanip.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.bitmanip.append

Takes an integral value, converts it to the given endianness, and appends it to the given range of ubytes (using put) as a sequence of T.sizeof ubytes starting at index. hasSlicing!R must be true.

Prototype

void append(T, std.system.Endian endianness, R)(
  R range,
  T value
)
if (canSwapEndianness!T && isOutputRange!(R, ubyte));

Parameters

NameDescription
T The integral type to convert the first T.sizeof bytes to.
endianness The endianness to write the bytes in.
range The range to append to.
value The value to append.

Example

import std.array;
auto buffer = appender!(const ubyte[])();
buffer.append!ushort(261);
assert(buffer.data == [1, 5]);

buffer.append!uint(369700095u);
assert(buffer.data == [1, 5, 22, 9, 44, 255]);

buffer.append!ubyte(8);
assert(buffer.data == [1, 5, 22, 9, 44, 255, 8]);

Example

assert(countTrailingZeros(1) == 0);
assert(countTrailingZeros(0) == 32);
assert(countTrailingZeros(int.min) == 31);
assert(countTrailingZeros(256) == 8);

Example

assert(countBitsSet(1) == 1);
assert(countBitsSet(0) == 0);
assert(countBitsSet(int.min) == 1);
assert(countBitsSet(uint.max) == 32);

Authors

Walter Bright, Andrei Alexandrescu, Jonathan M Davis, Alex Rønne Petersen, Damian Ziemba Amaury SECHET

License

Boost License 1.0.

Comments