bell notificationshomepageloginNewPostedit profile

Topic : Alternatives better to the binary "0b..." format? In our documentation, we write binary numbers like this: 1010 But we write hexadecimal numbers like this: 0xABAB Now, according to the GCC compiler - selfpublishingguru.com

10.05% popularity

In our documentation, we write binary numbers like this:
1010

But we write hexadecimal numbers like this:
0xABAB

Now, according to the GCC compiler conventions:

Numbers are normally written in decimal.
Binary numbers are preceded by 0b.
Hexadecimal numbers are preceded by 0x.

But in my mind, writing binary numbers as 0b1010 just looks wrong. But I can't tell my writers "don't do it because it looks wrong", especially because we write the hex numbers with a 0x prefix.

Are there any programmers out there who can weigh in on why I shouldn't use the 0b prefix? I need reinforcements :).


Load Full (3)

Login to follow topic

More posts by @Welton431

3 Comments

Sorted by latest first Latest Oldest Best

10% popularity

Traditional mathematical notation would be to use a subscript suffix containing the base of the number in decimal, e.g.:

The value 101111012 is equivalent to BD16.

This may or may not be appropriate for your use, depending on how familiar your readers are likely to be with this notation, and what purpose they will be reading it for. As suggested elsewhere, if the readers are likely to be using the documentation for work in a specific language then following the conventions of that language may well be the best bet.


Load Full (0)

10% popularity

I like more the Intel method: 10010b and 1f4dh. On the other hand, you should follow the convention that your reader are supposed to use (e.h. if you are describing a C API, you should use C convention.

On generic documentation, probably I would be more verbose, Something like 10010 bin, maybe with a mouse-over bubble which show the value in decimal and hexadecimal.


Load Full (0)

10% popularity

As somewhat alluded to by Chenmunka, if your documentation is generally in the context of a specific programming language and/or compiler, it is probably best to stick to what is required by those. However, I think this is also somewhat dependent on why the numbers are appearing in your documentation.

If you are referencing these numbers as something would directly appear in code, you should definitely use the language's standard format for the base you're using. On the other hand, if the documentation is simply bringing up the binary representation to explain a feature or illustrate a point, I think this is less necessary, so long as it is very clear that he number is binary.

The reason for the prefixes in code is that the compiler cannot know what base you're using without a hint. 1011 is valid decimal, hexadecimal, octal, and binary, so a prefix is required to denote which is being used. In your documentation you may be introducing the number with an appropriate context that makes this unnecessary:

Assuming the following binary representation of [foo]:

10010100111010011000

We can see that it has the properties [bar] and [baz].

In this case I think the 0b prefix would be unnecessary and possibly even make the documentation less readable, depending on the audiences familiar with programming languages.

In circumstances where large amounts of your documentation may have numbers like this, especially if the base may change depending on the context, introducing the notation early on (e.g. "We will be using the prefix "0b" to denote binary sequences and "0x" to denote hexadecimal sequences") might help as well.


Load Full (0)

Back to top