Division by two

Division by two

In mathematics, division by two or halving has also been called mediation or dimidiation.[1] The treatment of this as a different operation from multiplication and division by other numbers goes back to the ancient Egyptians, whose multiplication algorithm used division by two as one of its fundamental steps.[2] Some mathematicians as late as the sixteenth century continued to view halving as a separate operation,[3][4] and it often continues to be treated separately in modern computer programming.[5] Performing this operation is simple in decimal arithmetic, in the binary numeral system used in computer programming, and in other even-numbered bases.

Contents

Binary

In binary arithmetic, division by two can be performed by a bit shift operation that shifts the number one place to the right. This is a form of strength reduction optimization. For example, 1101001 in binary (the decimal number 105), shifted one place to the right, is 110100 (the decimal number 52): the lowest order bit, a 1, is removed. Similarly, division by any power of two 2k may be performed by right-shifting k positions. Because bit shifts are often much faster operations than division, replacing a division by a shift in this way can be a helpful step in program optimization.[5] However, for the sake of software portability and readability, it is often best to write programs using the division operation and trust in the compiler to perform this replacement.[6] An example from Common Lisp:

 (setq number #b1101001)   ; #b1101001  —  105
 (ash number -1)           ; #b0110100  —  105 >> 1 ⇒ 52
 (ash number -4)           ; #b0000110  —  105 >> 4 ≡ 105 / 2⁴ ⇒ 6

The above statements, however, are not always true when dealing with dividing signed binary numbers. Shifting right by 1 bit will divide by two, always rounding down. However, in some languages, division of signed binary numbers round towards 0 (which, if the result is negative, means it rounds up). For example, Java is one such language: in Java, -3 / 2 evaluates to -1, whereas -3 >> 1 evaluates to -2. So in this case, the compiler cannot optimize division by two by replacing it by a bit shift, when the dividend could possibly be negative.

Binary floating point

In binary floating-point arithmetic, division by two can be performed by decreasing the exponent by one (as long as the result is not a subnormal number). Many programming languages provide functions that can be used to divide a floating point number by a power of two. For example, the Java programming language provides the method java.lang.Math.scalb for scaling by a power of two,[7] and the C programming language provides the function ldexp for the same purpose.[8]

Decimal

The following algorithm is for decimal. However, it can be used as a model to construct an algorithm for taking half of any number N in any even base.

  • Write out N, putting a zero to its left.
  • Go through the digits of N in overlapping pairs, writing down digits of the result from the following table.
If first digit is Even Even Even Even Even Odd Odd Odd Odd Odd
And second digit is 0 or 1 2 or 3 4 or 5 6 or 7 8 or 9 0 or 1 2 or 3 4 or 5 6 or 7 8 or 9
Write 0 1 2 3 4 5 6 7 8 9

Example: 1738/2=?

Write 01738. We will now work on finding the result.

  • 01: even digit followed by 1, write 0.
  • 17: odd digit followed by 7, write 8.
  • 73: odd digit followed by 3, write 6.
  • 38: odd digit followed by 8, write 9.

Result: 0869.

From the example one can see that 0 is even.

If the last digit of N is odd digit one should add 0.5 to the result.

See also

  • One half
  • Median, a value that splits a set of data values into two equal subsets
  • Bisection, the partition of a geometric object into two equal halves
  • Dimidiation, a heraldic method of joining two coats of arms by splitting their designs into halves

References

  1. ^ Steele, Robert (1922), The Earliest arithmetics in English, Early English Text Society, 118, Oxford University Press, p. 82 .
  2. ^ Chabert, Jean-Luc; Barbin, Évelyne (1999), A history of algorithms: from the pebble to the microchip, Springer-Verlag, p. 16, ISBN 9783540633693 .
  3. ^ Jackson, Lambert Lincoln (1906), The educational significance of sixteenth century arithmetic from the point of view of the present time, Contributions to education, 8, Columbia University, p. 76 .
  4. ^ Waters, E. G. R. (1929), "A Fifteenth Century French Algorism from Liége", Isis 12 (2): 194–236, JSTOR 224785 .
  5. ^ a b Wadleigh, Kevin R.; Crawford, Isom L. (2000), Software optimization for high-performance computing, Prentice Hall, p. 92, ISBN 9780130170088 .
  6. ^ Hook, Brian (2005), Write portable code: an introduction to developing software for multiple platforms, No Starch Press, p. 133, ISBN 9781593270568 .
  7. ^ "Math.scalb". Java Platform Standard Ed. 6. http://java.sun.com/javase/6/docs/api/java/lang/Math.html#scalb(double,%20int). Retrieved 2009-10-11. 
  8. ^ Programming languages — C, International Standard ISO/IEC 9899:1999 , Section 7.12.6.6.

Wikimedia Foundation. 2010.

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

Look at other dictionaries:

  • Division (mathematics) — Divided redirects here. For other uses, see Divided (disambiguation). For the digital implementation of mathematical division, see Division (digital). In mathematics, especially in elementary arithmetic, division (÷ …   Wikipedia

  • division — [[t]dɪvɪ̱ʒ(ə)n[/t]] ♦♦ divisions 1) N UNCOUNT: oft with poss, oft N into pl n The division of a large unit into two or more distinct parts is the act of separating it into these parts. ...the unification of Germany, after its division into two… …   English dictionary

  • 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

  • Two Degrees — Infobox Company company name = Two Degrees company foundation = 1993 as Accounting Quest location = Seattle, with offices in Atlanta, Chicago, Denver, Phoenix, Portland key people = Brad Jackson, CEO, Tony Rojas, President num employees = 300… …   Wikipedia

  • Division par deux — En mathématiques, la division par deux a aussi été appelé la médiation ou la dimidiation[1]. La considération de cela comme étant une opération différente de la multiplication ou de la division par d autres nombres remonte aux Égyptiens de l… …   Wikipédia en Français

  • Two Nations Theory (Ireland) — The Two Nations Theory holds that the Northern Ireland Protestants are a distinct Irish nation.According to S.J. Connolly s Oxford Companion to Irish History (pg.585) this idea first appeared in the book Ulster As It Is (1896) by the Unionist… …   Wikipedia

  • division of opinion — In the practice of appellate courts, this term denotes such a disagreement among the judges that there is not a majority in favor of any one view, and hence no decision can be rendered on the case. But it also commonly denotes a division into two …   Black's law dictionary

  • division of opinion — In the practice of appellate courts, this term denotes such a disagreement among the judges that there is not a majority in favor of any one view, and hence no decision can be rendered on the case. But it also commonly denotes a division into two …   Black's law dictionary

  • 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

  • Division I — (or D I) is the highest level of intercollegiate athletics sanctioned by the National Collegiate Athletic Association in the United States. History D I schools are the major collegiate athletic powers, with larger budgets, more elaborate… …   Wikipedia

Share the article and excerpts

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