View source code
Display the source code in std/conv.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aBugzilla issue.
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 usinglocal clone.
Function std.conv.bitCast
Takes the raw bits of a value and reinterprets them as a different type.
ref T bitCast(T, S)(
ref S value
)
if (T .sizeof <= S .sizeof);
Parameters
Name | Description |
---|---|
T | the new type. |
value | the value to reinterpret. |
Returns
a reference to the reinterpreted value.
Example
uint n = 0xDEADBEEF;
version (LittleEndian)
writeln(n .bitCast!(ubyte[4])); // [0xEF, 0xBE, 0xAD, 0xDE]
version (BigEndian)
writeln(n .bitCast!(ubyte[4])); // [0xDE, 0xAD, 0xBE, 0xEF]
Authors
Walter Bright, Andrei Alexandrescu, Shin Fujishiro, Adam D. Ruppe, Kenji Hara
License
Copyright © 1999-2025 by the D Language Foundation | Page generated by ddox.