Leading zero
Encyclopedia
A leading zero is any 0
0 (number)
0 is both a numberand the numerical digit used to represent that number in numerals.It fulfills a central role in mathematics as the additive identity of the integers, real numbers, and many other algebraic structures. As a digit, 0 is used as a placeholder in place value systems...

 digits
Numerical digit
A digit is a symbol used in combinations to represent numbers in positional numeral systems. The name "digit" comes from the fact that the 10 digits of the hands correspond to the 10 symbols of the common base 10 number system, i.e...

, that lead a number string in a positional notation
Positional notation
Positional notation or place-value notation is a method of representing or encoding numbers. Positional notation is distinguished from other notations for its use of the same symbol for the different orders of magnitude...

. For example, James Bond
James Bond
James Bond, code name 007, is a fictional character created in 1953 by writer Ian Fleming, who featured him in twelve novels and two short story collections. There have been a six other authors who wrote authorised Bond novels or novelizations after Fleming's death in 1964: Kingsley Amis,...

's famous identifier, 007, has two leading zeros. Leading zeros occupy most significant digits, which could be left blank or omitted for the same numeric value. Usual decimal
Decimal
The decimal numeral system has ten as its base. It is the numerical base most widely used by modern civilizations....

 notation of integer
Integer
The integers are formed by the natural numbers together with the negatives of the non-zero natural numbers .They are known as Positive and Negative Integers respectively...

s does not use leading zeros except for the zero itself
0 (number)
0 is both a numberand the numerical digit used to represent that number in numerals.It fulfills a central role in mathematics as the additive identity of the integers, real numbers, and many other algebraic structures. As a digit, 0 is used as a placeholder in place value systems...

, which would be denoted as an empty string
Empty string
In computer science and formal language theory, the empty string is the unique string of length zero. It is denoted with λ or sometimes Λ or ε....

 otherwise.

Occurrence

Often, leading zeros are found on non-electronic digital displays or on such electronic ones as seven-segment display
Seven-segment display
A seven-segment display , or seven-segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot-matrix displays...

s, that contain fixed sets of digits. These devices include manual counters, stopwatch
Stopwatch
A stopwatch is a handheld timepiece designed to measure the amount of time elapsed from a particular time when activated to when the piece is deactivated. A large digital version of a stopwatch designed for viewing at a distance, as in a sports stadium, is called a stopclock.The timing functions...

es, odometer
Odometer
An odometer or odograph is an instrument that indicates distance traveled by a vehicle, such as a bicycle or automobile. The device may be electronic, mechanical, or a combination of the two. The word derives from the Greek words hodós and métron...

s, and digital clocks. Leading zeros are also generated by many older computer programs when creating values to assign to new records, accounts and other files, and as such are likely to be used by utility billing systems, human resources information systems and government databases. Many digital camera
Digital camera
A digital camera is a camera that takes video or still photographs, or both, digitally by recording images via an electronic image sensor. It is the main device used in the field of digital photography...

s and other electronic media recording devices use leading zeros when creating and saving new files to make names of the equal length.

A leading zero appears in roulette
Roulette
Roulette is a casino game named after a French diminutive for little wheel. In the game, players may choose to place bets on either a single number or a range of numbers, the colors red or black, or whether the number is odd or even....

 in the United States, where '00' is distinct from '0' (a wager on '0' will not win if the ball lands in '00', and vice versa). Sports where competitors are numbered follow this as well; a stock car numbered '07' would be considered distinct from one numbered '7'. This is most common with single-digit numbers.

Advantages

Leading zeros are used to make ascending order of numbers correspond with alphabetical order: e.g., 11 comes alphabetically before 2, but after 02. (See, e.g., ISO 8601
ISO 8601
ISO 8601 Data elements and interchange formats – Information interchange – Representation of dates and times is an international standard covering the exchange of date and time-related data. It was issued by the International Organization for Standardization and was first published in 1988...

.) This does not work with negative numbers, though, whether leading zeroes are used or not: −23 comes alphabetically after −01, −1, and −22, although it is less than all of them.

Leading zeros can also be used to prevent fraud by filling in character positions that might normally be empty.

0 as a prefix

A prefix 0 is used in the C programming language
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

, Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

, Perl, the Unix shell
Unix shell
A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems...

 bash, and other languages to specify octal
Octal
The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7. Numerals can be made from binary numerals by grouping consecutive binary digits into groups of three...

 numbers (and 0x means hexadecimal
Hexadecimal
In mathematics and computer science, hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen...

), and therefore, 0020 does not represent 2010 ( 2*101 + 0*100 ), but rather 208=1610 ( 2*81 + 0*80 = 1*101 +6*100). Decimal numbers written with leading zeros will likely be interpreted as octal, and will generate errors—not just unexpected results—if they contain '8' or '9' since these digits do not exist in octal. This behavior can be quite a nuisance when writing scripts to work with sequences of strings which have embedded zero-padded decimal
Decimal
The decimal numeral system has ten as its base. It is the numerical base most widely used by modern civilizations....

numbers (typically file names) to facilitate ASCII sorting (see above).
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK