Created
October 9, 2023 15:04
-
-
Save run-dlang/a3493943a78b671f46d45fd7b626f594 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io. Run with '-preview=bitfields'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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