Power of two

Power of two

In mathematics, a power of two is any of the integer powers of the number two; [cite book |title=Schaum's Outline of Theory and Problems of Essential Computer Mathematics |first=Seymour |last=Lipschutz |year=1982 |id=ISBN 0070379904 |pages=3] in other words, two multiplied by itself a certain number of times. [cite book |title=Mathematics Masterclasses |first=Michael J. |last=Sewell |year=1997 |id=ISBN 0198514948 |pages=78] Note that one is a power (the zeroth power) of two. Written in binary, a power of two always has the form 100...0, just like a power of ten in the decimal system.

Because two is the base of the binary system, powers of two are important to computer science. Specifically, two to the power of "n" is the number of ways the bits in a binary integer of length "n" can be arranged, and thus numbers that are one less than a power of two denote the upper bounds of integers in binary computers (one less because 0, not 1, is used as the lower bound). As a consequence, numbers of this form show up frequently in computer software. As an example, a video game running on an 8-bit system, might limit the score or the number of items the player can hold to 255 — the result of a byte, which is 8 bits long, being used to store the number, giving a maximum value of 28−1 = 255.

Powers of two also measure computer memory. A byte is eight bits, resulting in the possibility of 256 values (28). A kilobyte is 1,024 (210) bytes (the term "byte" is often defined as a collection of bits rather than the strict definition of an 8-bit quantity.) Standards prefer the word kibibyte, as "kilobyte" also means 1,000 bytes. Nearly all processor registers have sizes that are powers of two, 32 or 64 being most common (see word size).

Powers of two occur in a range of other places as well. For many disk drives, at least one of the sector size, number of sectors per track, and number of tracks per surface is a power of two. The logical block size is almost always a power of two.

Numbers which are not powers of two occur in a number of situations such as video resolutions, but they are often the sum or product of only two or three powers of two, or powers of two minus one. For example, 640 = 512 + 128, and 480 = 32 × 15. Put another way, they have fairly regular bit patterns.

A prime number that is one less than a power of two is called a Mersenne prime. For example, the prime number 31 is a Mersenne prime because it is 1 less than 32 (25). Similarly, a prime number (like 257) that is one more than a power of two is called a Fermat prime. The exponent will itself be a power of two. See Fermat number. A fraction that has a power of two as its denominator is called a dyadic rational.

The 0th through 40th powers of 2

As demonstrated above, the algorithm yieds the correct value of 4096. It should be noted that the nearest power to 2689 happens to be 2048; however, this algorithm is designed only to give the "next highest" power of two to a given number, not the nearest power of two.

A C++ version of this code for the integer type T would be:

T nexthigher(T k) { k--; for (int i=1; i> i; return k+1;}

References


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Epic Mickey 2: The Power of Two — Разработчики Blitz Games Stud …   Википедия

  • metre to the power minus two per second — atvirkštinis kvadratinis metras sekundei statusas T sritis Standartizacija ir metrologija apibrėžtis Dalelių įtėkio spartos arba dalelių srovės tankio matavimo vienetas: m⁻²/s. atitikmenys: angl. metre to the power minus two per second;… …   Penkiakalbis aiškinamasis metrologijos terminų žodynas

  • metre to the power minus two — vienetas kvadratiniam metrui statusas T sritis Standartizacija ir metrologija apibrėžtis Fotoninės ekspozicijos arba dalelių įtėkio matavimo vienetas: m⁻². atitikmenys: angl. metre to the power minus two; one per square metre rus. единица на… …   Penkiakalbis aiškinamasis metrologijos terminų žodynas

  • Two-wheel tractor — in Italy (2008) Two wheel tractor or walking tractor are generic terms understood in the USA and in parts of Europe to represent a single axle tractor, which is a tractor with one axle, self powered and self propelled, which can pull and power… …   Wikipedia

  • Power ring (DC Comics) — This article is about the Green Lantern Corps weapon. For the supervillains, see Power Ring (DC Comics). Power ring The Green Lantern Corps rings. Publication information …   Wikipedia

  • power, balance of — ▪ international relations       in international relations, the posture and policy of a nation or group of nations protecting itself against another nation or group of nations by matching its power against the power of the other side. States can… …   Universalium

  • Power supply — For the Budgie album, see Power Supply (album). A vacuum tube rackmount adjustable power supply, capable of +/ 1500 volts DC, 0 to 100mA output, with amperage limiting capability. A power supply is a device that supplies electrical energy …   Wikipedia

  • Two Trains Running — Infobox Play name = Two Trains Running image size = 150px caption = Broadway production poster writer = August Wilson series = The Pittsburgh Cycle genre = Drama setting = the Hill District of Pittsburgh, 1969 subject = The uncertain future… …   Wikipedia

  • Power Ballads (album) — Infobox Album | Name = Power Ballads The Greatest Driving Anthems in the World... Ever! Type = Compilation album Artist = Various Artists Released = April 27 2004 (Track List 1), February 14 2004 (Track List 2), October 11 2004 (Track List… …   Wikipedia

  • Two's complement — The two s complement of a binary number is defined as the value obtained by subtracting the number from a large power of two (specifically, from 2 N for an N bit two s complement).A two s complement system or two s complement arithmetic is a… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”