Navigation
  • Home
  • Recent
  • Most Active
  • Popular
  • Blog
  • Credits
  • RSS
  •   Interaction
  • Register
  • Statistics
  •   Help
  • Suggestions
  • Contact Us
  • How to Edit
  • Help



  • [Edit]


    For the Indigo Girls song, see Swamp Ophelia.

    In mathematics, a power of two is any of the nonnegative integer powers of the number two; in other words, two times itself a certain number of times. Note that one is a power (the zeroth power) of two. Written in binary, a power of two always has the form 10000...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 (23) bits, and a kilobyte is 1,024 (210) bytes (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).


        Power of two
            The 0th through 40th powers of 2
            Powers of two whose exponents are powers of two
            Other recognisable powers of two
            Fast algorithm to check if a number is a power of two
            Fast algorithm to convert any number into nearest power of two number

    top

    The 0th through 40th powers of 2



    top

    Powers of two whose exponents are powers of two

    Because modern memory cells and registers often hold a number of bits which is a power of two, the most frequent powers of two to appear are those whose exponent is also a power of two. For example:

    21 = 2

    22 = 4

    24 = 16

    28 = 256

    216 = 65,536

    232 = 4,294,967,296

    264 = 18,446,744,073,709,551,616

    2128 = 340,282,366,920,938,463,463,374,607,431,768,211,456

    2256 = 115,792,089,237,316,195,423,570,985,008,687,907,853,269,984,665,640,564,039,457,584,007,913,129,639,936


    Several of these numbers represent the number of values representable using common computer data types. For example, a 32-bit word consisting of 4 bytes can represent 232 distinct values, which can either be regarded as mere bit-patterns, or are more commonly interpreted as the unsigned numbers from 0 to 232−1, or as the range of signed numbers between −231 and 231−1.

    top

    Other recognisable powers of two

    210 = 1,024

      the digital approximation of the kilo-, or 1,000 multiplier, which causes a change of prefix. For example: 1,024 bytes = 1 kilobyte (or kibibyte).
      This number has no special significance to computers, but is important to humans because we make use of powers of ten.
    224 = 16,777,216

      This number is the result of using the three-channel RGB system, with 8 bits for each channel, or 24 bits in total.

    top

    Fast algorithm to check if a number is a power of two

    The binary representation of integers makes it possible to apply a very fast test to determine whether a given integer x is a power of two:

    x is a power of two Leftrightarrow (x & (x − 1)) equals zero.


    where & is a bitwise logical '''AND''' operator. Note that zero is incorrectly considered a power of two by this test. Therefore a more thorough (but slightly slower) test would be:

    x is a power of two Leftrightarrow (x > 0) and ((x & (x − 1)) == 0)


    Examples:


    top

    Fast algorithm to convert any number into nearest power of two number

    The following formula finds the nearest power of two with respect to binary logarithm of a given value x > 0:

    2^


    It does not, however, find the nearest power of two with respect to the actual value. For example, 47 is nearer to 16 than it is to 64, but previous formula rounds it to 64.

    If x is an integer value, following steps can be taken to find the nearest value (with respect to actual value rather than the binary logarithm) in a computer program:
      Assume that all bits k < 0 are zero. Then, if bit k-1 is zero, the result is 2^k. Otherwise the result is 2^.




     
    Search more:
     

       
    Source Privacy License Download Contact Us Atlas
    Scientus.org Dictionary (Yet Another Wiki) RC : 1.39
    MIT OpenCourseWare
    This article is licensed under the GNU Free Documentation License [copyleft]. It uses material from the Wikipedia article "Power of two". link