Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Since this is all new, there might still be time to establish a consensus before this style feature too ends up "all over the place" (like upper/lower case hex, upper/lower case integer constant su...
Answer
#1: Initial revision
Since this is all new, there might still be time to establish a consensus before this style feature too ends up "all over the place" (like upper/lower case hex, upper/lower case integer constant suffices etc). Luckily we can lean on established computer science in this case - there are already best engineering practices for how to write numbers with various bases. If using those present best practices, then we end up with something like this: --- **Decimal integer/floating point constants (base 10)** Since programming sorts under the domain of engineering, these should respect [engineering notation](https://en.wikipedia.org/wiki/Engineering_notation), which means that decimal values are conveniently expressed is multiples of 10<sup>3</sup> or 10<sup>-3</sup>. That is: tera, giga, mega, kilo, milli, micro, nano, pico and so on. ```c // appropriate style examples: 1'000'000 1'000'000.0 0.000'000 .000'000 // BAD style examples, do not use: 1'0000'0000 1'2'3 12'34'56 12.34'56'78 ``` **Binary constants (base 2)** Binary numbers are by convention always grouped either by nibbles or bytes. Grouping them by any larger unit will become unreadable. Grouping them as anything else but groups of 4 is senseless, except for cases where you have a number of bits not divisible by 4. In that case, remaining bits are placed to the left. ```c // appropriate style examples: 0b0000'0000'0000'0000 0b00000000'00000000 0b10'1010'1010 // BAD style examples, do not use: 0b00'00'00'00 0b0000000000000000'0000000000000000 0b1010'1010'10 ``` **Hexadecimal constants (base 16)** Hex might be grouped in several different ways. Sometimes it might make sense to group it on byte level, sometimes as 16 bit words. 32 bit words without decimal separators are harder to read. Breaking up nibbles doesn't make sense either. In case of numbers that aren't divisible by 16 bits, remaining bits are placed to the left. ```c // appropriate style examples: 0x00'00'00'00 0x0000'0000 0xAA'BBCC // BAD style examples, do not use: 0x0'0'0'0 0x0000000000000000'0000000000000000 0xAABB'CC ```