5

The proper way to denote hex, or base 16, is to prepend 0x

Conversely, what is the proper way to denote decimal/base 10?

user2018084
  • 2,064
  • 9
  • 38
  • 50
  • 1
    You don't need to denote the base. Unless you indicate its `base 16` or `base 2` its assumed to be `base 10`. – Ramhound Mar 04 '15 at 21:47
  • Some languages denote Octal with a leading 0. – ChrisInEdmonton Mar 04 '15 at 21:50
  • 1
    @Ramhound I know you're right. Most would assume that it is base 10 and it is not necessary to indicate that, however I do know there is a way to explicitly denote base 10. – user2018084 Mar 04 '15 at 21:51
  • To those who downvoted I'm assuming two things, either 1) It's not necessary. I know that, but I also know that there a formal way to explicitly denote base 10 or 2) You assume it's trivial to find it on the internet, but I have been unable to find it on google so if you could take the time to post the answer while you downvote, you would make me a happy camper! :) – user2018084 Mar 04 '15 at 21:52
  • "It's trivial to find it on the internet, but I have been unable to find it on google" doesn't make sense ... – DavidPostill Mar 04 '15 at 21:54
  • Synonym for a number base is *radix*. I have occasionally seen the decimal radix specified in a number with the suffix "R10", e.g. 123R10. But that was only in text, not a programming language. – sawdust Mar 04 '15 at 21:58
  • Why? if it's trivial to find you should be able to find it yourself :/ – DavidPostill Mar 04 '15 at 21:58
  • As you have have Computer Science in the question title perhaps you should be asking on [Computer Science Stack Exchange](http://cs.stackexchange.com/) – DavidPostill Mar 04 '15 at 22:07
  • @user2018084 - I can safely say that you are not getting downvotes because the formal synonym is well known or you didn't show effort. – Ramhound Mar 04 '15 at 22:12
  • If you are producing an essay or documentation then you can use subscript notation if your typography allows it; or you can define your own notation, eg by stating in a prefix "_In the examples below 0xNNN denotes a number in hexadecimal notation and 0dNNN denotes a number in decimal notation_". Otherwise, if you don't need a shorthand representation, just write `(base 10)` in parenthesis after the number. In a programming context you are constrained by the language you are using, but in a written text you can use whatever you think will be clearest to its recipients. – AFH Mar 04 '15 at 23:39

3 Answers3

3

what is the proper way to denote decimal/base 10?

In mathematical numeral systems, the radix or base is the number of unique digits, including zero, used to represent numbers in a positional numeral system. For example, for the decimal system (the most common system in use today) the radix is ten, because it uses the ten digits from 0 through 9.

In any positional numeral system (except unary, where the radix is 1), the number x and its base y are conventionally written as enter image description here, although for base ten the subscript is usually assumed and not written, as it is the most common way to express value. For example, enter image description here (in the decimal system) represents the number one hundred, whilst enter image description here (in the binary system with base 2) represents the number four.

Source Radix


Further reading

DavidPostill
  • 153,128
  • 77
  • 353
  • 394
  • Just as the "E" suffix notation can substitute for the exponent written as a superscript, I've seen an "R" suffix in place of the radix subscript. – sawdust Mar 04 '15 at 22:35
2

The 0 and 0x prefix are the C programming language's way of expressing octal/hex, and has become popular due to the popularity and ubiquity of C. That convention itself may have come from earlier languages or conventions.

Various other standards for expressing have been used over time. 6502 assembly prefixed hex with a $. In a lot of Z80 and early x86 assembly, you'll see a trailing H. Some dialects of BASIC used an & or something like &H.

So this is going to be specific to the programming language you are working with. Many languages, especially ones created since the late 80's or so use C's standards for things. Outside of a programming language context, you should probably use mathematical notation standards or write a word denoting the base ("base 10" or "decimal") if there could be confusion.

LawrenceC
  • 73,030
  • 15
  • 129
  • 214
1

I really, really do like the answer from Ramhound's comment. If you simply don't specify a base, the general assumption is that it is base 10.

If you want to be very explicit, you could use HTML "5<SUB>10</SUB>" (or "5<sub>10</sub>" for those who prefer lowercase HTML) to be rendered as "510". In text, you can use "5 base 10".

Note that 0x is not a universal way to specify hexadecimal. The 0x prefix is used by the language of C, and other languages similar to C. In typical x86 assembly, one uses an H suffix (so 0x768 in C is the same thing as 768H in x86 assembly). Embedded programming: numbers says that the H suffix is for "Intel and TI assembly language". That same web page notes that for "Freescale assembly language", the syntax is to prepend a dollar sign ("$768").

In all of these languages (C, Intel Assembly, and Freescale assembly), the syntax for a base 10 number is to just specify the number, with no special text needed to be prepended or suffixed.

Other methods could be used (like adding an underscore followed by a radix value, which may be easier to type than relying on using subscript font rendering), or you could use any other custom method that you describe at the start of your writing/lecture/whatever, but ultimately, if you don't specify something specific, then people will be inclined to use their assumptions.

Part of communication is to know your audience. (That's basic communication theory, not limited to specifically computers.) If your audience includes a bunch of C programmers, then 0x just implies hexadecimal. If your audience doesn't, then 0x768 looks like a multiplication problem, and equates to zero. If you're interacting with a group of people who are familiar with a particular syntax/language/convention, then use what they are familiar with.

The art of computer programming is basically a way to communicate the ideas of what you want a computer to do. The best way to communicate is generally to use what the audience expects. And, as you can see from multiple comments here, the general tradition is to just assume base 10 unless there is an indication (like a notation like "0xblah") or other reason (like context) to believe that the base is something else.

Just as another example thrown out there: if I see 99-10-12-16-23-20, then I don't automatically start thinking "18". I start to think that looks like a MAC-48 address of a network card, written in the format used by IEEE's OUI list and Microsoft Windows (and not Unix)... interesting that it has no digits that are exclusively hexadecimal. But if I was expecting a network address, then I would probably assume that those are likely hexadecimal digits.

I have seen instructors of college level courses will sometimes want to write a bunch of numbers and be very clear about the bases. In those (not incredibly common) situations, what they typically did is use the subscript notation, unless they knew that there handwriting was sloppy, in which case they would also add some parenthesis as shown by the answer given by DavidPostill.

TOOGAM
  • 15,243
  • 4
  • 41
  • 58