Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do most languages not allow binary numbers?

Why do most computer programming languages not allow binary numbers to be used like decimal or hexadecimal?

  • In VB.NET you could write a hexadecimal number like &H4
  • In C you could write a hexadecimal number like 0x04

Why not allow binary numbers?

  • &B010101
  • 0y1010

Bonus Points!... What languages do allow binary numbers?


Edit

Wow! - So the majority think it's because of brevity and poor old "waves" thinks it's due to the technical aspects of the binary representation.

like image 773
user51886 Avatar asked Jan 27 '09 15:01

user51886


People also ask

Can binary be translated to any language?

Of course it's possible. Machine language is a programming language, like any other. Any Turing-complete language can be translated into any other Turing-complete language, given enough time and effort. For instruction sets, the process is called Binary Translation.

Do all coding languages use binary?

The short answer is no. Computer languages are not written in binary. However, the compiler or interpret eventually translate the language into binary through a number of steps.

Why is machine language called binary language Why is it not popular used by programmers?

a computer(the machine) operates on electricity. thus,it can understand only electricity signals that are just two ON and OFF or high voltage or low voltage. thus it needs a language that uses just 2 unique symbols to represent these 2 states of electricity.

Is binary language still used?

Binary is still the primary language for computers and used with electronics and computer hardware for the following reasons. It is a simple and elegant design. Binary's 0 and 1 method is quick to detect an electrical signal's off (false) or on (true) state.


2 Answers

Because hexadecimal (and rarely octal) literals are more compact and people using them usually can convert between hexadecimal and binary faster than deciphering a binary number.

Python 2.6+ allows binary literals, and so do Ruby and Java 7, where you can use the underscore to make byte boundaries obvious. For example, the hexadedecimal value 0x1b2a can now be written as 0b00011011_00101010.

like image 108
phihag Avatar answered Nov 15 '22 23:11

phihag


In C++0x with user defined literals binary numbers will be supported, I'm not sure if it will be part of the standard but at the worst you'll be able to enable it yourself

int operator "" _B(int i);

assert( 1010_B == 10);
like image 44
Motti Avatar answered Nov 15 '22 23:11

Motti