Number

boapast's avatar
Published Feb 5, 2025
Contribute to Docs

A number is a primitive data type used to represent mathematical values and is commonly used in arithmetic operations, data encoding, and other computations. Examples of numbers include 0, -1, 0.3, and other numeric values.

Note: In some programming languages, decimals may be treated as a separate data type, such as float or double.

Number Systems

A number system defines how a number is represented. The representation depends on the number of digits (base) it uses. The main number systems are:

  • Decimal System (Base 10): This system uses 10 digits, 0-9. Each digit’s place value corresponds to a power of 10.
  • Binary System (Base 2): The binary system uses only two digits, 0 and 1, to represent values. It is extensively used by computers and electronic devices to represent HIGH (1) and LOW (0) states.
  • Octal System (Base 8): The octal system uses 8 digits, 0-7. It is used in computer systems to represent values like UTF-8 characters and file permissions in UNIX systems.
  • Hexadecimal System (Base 16): The hexadecimal system uses 16 digits, where 0-9 are taken directly from the decimal system and 10-15 are represented by letters A-F (i.e., 10 is A, 11 is B, 12 is C, 13 is D, 14 is E, and 15 is F). It is commonly used in computer science, particularly for representing memory addresses.

Basic Arithmetic Operations on Two Numbers (JavaScript)

This code calculates the sum, difference, division, and product of the given numbers and prints the results to the console:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn more on Codecademy