Skip to content

Conversation

@cfriedt
Copy link
Member

@cfriedt cfriedt commented Nov 3, 2024

Obviously, everyone knows that there are 8 bits per byte, so there isn't a lot of magic happening, per se, but it's also helpful to clearly denote where the magic number 8 is referring to the number of bits in a byte.

Occasionally, 8 will refer to a field size or offset in a structure, MMR, or word. Occasionally, the number 8 will refer to the number of bytes in a 64-bit value (which should probably be replaced with sizeof(uint64_t)).

For converting bits to bytes, or vice-versa, let's use BITS_PER_BYTE for clarity (or other appropriate BITS_PER_* macros).

@cfriedt cfriedt force-pushed the apply-bits-per-byte branch 3 times, most recently from f2652c6 to efd97c1 Compare November 3, 2024 15:34
Obviously, everyone knows that there are 8 bits per byte, so
there isn't a lot of magic happening, per se, but it's also
helpful to clearly denote where the magic number 8 is referring
to the number of bits in a byte.

Occasionally, 8 will refer to a field size or offset in a
structure, MMR, or word. Occasionally, the number 8 will refer
to the number of bytes in a 64-bit value (which should probably
be replaced with `sizeof(uint64_t)`).

For converting bits to bytes, or vice-versa, let's use
`BITS_PER_BYTE` for clarity (or other appropriate `BITS_PER_*`
macros).

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt cfriedt force-pushed the apply-bits-per-byte branch from efd97c1 to 3330055 Compare November 3, 2024 15:45
@cfriedt cfriedt changed the title treewide: use BITS_PER_BYTE macro instead of the magic number 8 sys: util: use BITS_PER_BYTE macro instead of the magic number 8 Nov 3, 2024
@cfriedt cfriedt marked this pull request as ready for review November 3, 2024 17:30
Copy link
Contributor

@jfischer-no jfischer-no left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously, everyone knows that there are 8 bits per byte, so
there isn't a lot of magic happening, per se, but it's also
helpful to clearly denote where the magic number 8 is referring
to the number of bits in a byte.

That is an exaggeration. Everyone knows that an octet has eight bits. A byte is not necessarily so.

@cfriedt
Copy link
Member Author

cfriedt commented Nov 4, 2024

That is an exaggeration. Everyone knows that an octet has eight bits. A byte is not necessarily so.

In this context, byte was used as a synonym for octet. If you feel that isn't necessarily true, please feel free to suggest changes.

@decsny decsny removed their request for review November 4, 2024 17:21
@nashif nashif merged commit 9504034 into zephyrproject-rtos:main Nov 16, 2024
37 checks passed
@cfriedt cfriedt deleted the apply-bits-per-byte branch November 21, 2024 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants