Binary system sums

Arrojeria, Eustakio

Elhuyar Zientziaren Komunikazioa

Lizaso, Pili

Informatika Saila

Elhuyar Fundazioa

After viewing base conversions in numbering systems (ELHUYAR. We have seen Science and Technology in number 27) and to understand what it means to work in the binary system, on this occasion we propose: Sum of numbers in base 2 or binary system.

Perhaps the first thing you can think of is to pass the numbers to base 10, make the sum in the decimal system and then pass the result to base 2, but although the result obtained is the correct one, this would not be the most correct way. The sums can also be done in the binary system and we ask you here.

When making the sums in the decimal system, put all the first numbers on par, that is, the first ones to the height of the ones, the decimals to the pair of the ten, etc. and then we start to make the sum by the right column, saving a number for the head (for the next column) each time we go through ten.

Something similar must be done in the binary system. Yes, every time we pass two in this system we must keep one more for the head.

Let's see an example:

Suppose we have 4 6-digit sumands. The sum would be:


Parts of the program:

  • 10-110: The number of digits in the summaries (N1) and the number of sumands (N2) are selected. In this way the user will define the difficulty of the sum.
  • 120 to 180: N2 binary numbers formed by N1 digits are randomly extracted.
  • 190-360: The sum is done leaving the result in the variable SUM$. The sum will begin with the right column (200). When attaching a column, consider if there is anything first for the head (210). Since once the sum of each column is calculated, the one to be saved for the overall result can be Ø or 1, the function MOD 2 (240) must be used. Every time you pass Bit (or Ø) 1 will be added to the led. Adding 1 to a binary number means that, starting from the right, 1 substitutes Øaz for 1 when Ø (260-310).J. It will be added to the result obtained in the column “Ø” or “1” hour (340). If after joining column J (left) there is something for the head, it will be necessary to add to the addition string on the left (360).
  • 370-410: Presentation of the sum on screen.
  • 420-480: Save the entered until the user clicks <RETURN> in the SAR$ variable.
  • 500-570: Verification of the entered result.
  • 580-630: Possibility to continue or leave the program.
Babesleak
Eusko Jaurlaritzako Industria, Merkataritza eta Turismo Saila