Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created October 9, 2023 15:03
Show Gist options
  • Save run-dlang/ec06973ca666ac628a80420f48830925 to your computer and use it in GitHub Desktop.
Save run-dlang/ec06973ca666ac628a80420f48830925 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io. Run with '-preview=bitfields'
import std;
struct integer
{
bool
sign: 1,
bit1: 1,
bit2: 1,
bit3: 1,
bit4: 1,
bit5: 1,
bit6: 1,
bit7: 1
;
}
void main()
{
writeln("Structure size: ", integer.sizeof, " byte.");
integer data = {0,1,1,0,0,1,0,0};
writeln(data);
writeln("Signed integer: ", data.sign);
writeln("First bit is set: ", data.bit1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment