Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created October 9, 2023 15:04
Show Gist options
  • Save run-dlang/a3493943a78b671f46d45fd7b626f594 to your computer and use it in GitHub Desktop.
Save run-dlang/a3493943a78b671f46d45fd7b626f594 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io. Run with '-preview=bitfields'
import std;
alias bit = bool;
struct integer
{
bit
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