How to designate different systems with numbers when typing?

I know this is not really a programming issue, but it is related to the subject for me. How do you designate different number systems only in text? (In the text, I mean the ability to dial the desired speed, and not copy it to another program.) For example, if I have a number in base 2, how do I dial it so that others can understand that this is the number of base 2. On paper you can do something like (1001) 2, where 2 is a small index. Is there any particular character that you must enter before 2 so that others understand it as an index? (The exponentiation uses the ^ symbol for this). Or is all this just by chance, and there is no standard in it?

+4
source share
5 answers

The consensus I saw is that since the caret indicates the superscript (as for exponentiation), the underscore denotes the index. Thus, the most “literal” way to translate your example to ASCII is 1001_2. I agree with JacobM; the 0b prefix is ​​unambiguous and is unlikely to be misunderstood.

+1
source

Convention in many programming languages

0b1001 

where "b" stands for binary code. Other conventions include starting at 0x for a hexadecimal number and starting at 0 (except for other digits) for octal.

+3
source

For hex code, you must prefix it with 0x .

 0xFF 

For binary, a 0b

 0b101 

For Octal a 0o

 0o44 

Alternatively, be more explicit?

 dec(123) hex(0AF) bin(101) oct(111) 
+1
source

I think a lot of this will depend on how / why / what you want to do with the data at the end.

It’s logical for me to use ^, as it prints quickly, but it might be misinterpreted by someone unfamiliar with the designation.

0
source

Designations for the base vary depending on the programming language (as I said in the commentary on this question ).

  • Decimal notation has a default value (no special notation).
  • Hexadecimal is prefixed with # or 0x or uses the suffix h : 0xA0 , #A0 or A0h .
  • Some languages ​​use the prefix 0 to represent octal notation (for example, 0777 ).
  • Binary notation is less common (the hexadecimal system is most often used because it makes the recording a little more compact and ends up using the correct fill for octets). However, you can use 0b1010 or 1010b . Again, this depends on the language and whether the compiler supports it.

All of the above depends on the programming language. If it is only for writing text, any of these conventions should do. Of course, if you are writing a book, do not change the agreement that you use in the middle ...

0
source

All Articles