{"id":5483,"date":"2023-11-20T15:28:11","date_gmt":"2023-11-20T14:28:11","guid":{"rendered":"https:\/\/msxitalia.org\/?p=5483"},"modified":"2023-11-20T15:28:11","modified_gmt":"2023-11-20T14:28:11","slug":"msx-basic-lezione-7","status":"publish","type":"post","link":"https:\/\/msxitalia.org\/en\/msx-basic-lezione-7\/","title":{"rendered":"MSX BASIC \u2013 lesson 7"},"content":{"rendered":"<div class=\"\" dir=\"auto\">\n<div id=\":r49d:\" class=\"x1iorvi4 x1pi30zi x1swvt13 xjkvuk6\" data-ad-comet-preview=\"message\" data-ad-preview=\"message\">\n<div class=\"x78zum5 xdt5ytf xz62fqu x16ldp7u\">\n<div class=\"xu06os2 x1ok221b\">\n<div class=\"xdj266r x11i5rnm xat24cr x1mh8g0r x1vvkbs x126k92a\">\n<h1 dir=\"auto\"><img decoding=\"async\" data-src=\"https:\/\/msxitalia.org\/wp-content\/uploads\/2023\/11\/Corso-Basic-MSX1-OC-300x225.jpg\" class=\"size-medium wp-image-5338 aligncenter lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"\" width=\"300\" height=\"225\" \/><noscript><img decoding=\"async\" class=\"size-medium wp-image-5338 aligncenter\" src=\"https:\/\/msxitalia.org\/wp-content\/uploads\/2023\/11\/Corso-Basic-MSX1-OC-300x225.jpg\" alt=\"\" width=\"300\" height=\"225\"><\/noscript><\/h1>\n<h1 dir=\"auto\" style=\"text-align: center;\">\u201cMSX BASIC\u201d COLUMN by Orazio Cacciola (part 7)<\/h1>\n<h2 style=\"text-align: center;\">Mathematical, relational and logical operators<\/h2>\n<\/div>\n<p>Today I will talk about the various operators that are fundamental in our Basic MSX programs.<br \/>\nThe mathematical operators, which we all know and use in our daily lives, such as addition (+), subtraction (-), multiplication (*) and division (\/), are the fundamental basis for our calculations.<br \/>\nPRINT 21+32; or PRINT 50-25; or PRINT 25*4; to finish PRINT 50\/2.<br \/>\nBy doing this, we will have our immediate results and how to use a calculator, but by inserting them into our programs, we can combine even more operations, also using them with variables. Remember that multiplications and divisions will take precedence over additions and subtractions. But this problem can be overcome by inserting the calculations that we want to give precedence inside the round brackets.<\/p>\n<p>To give an example: 100 A=52*(25-10) + (20\/2) + 22.<br \/>\nLet&#039;s examine the line above: first everything inside the brackets will be calculated: A=52*15+10+22. Then it will calculate in order of sign priority:<br \/>\nA=780+10+22 and finally the remainder, since the operators are all sums.<br \/>\nRemember that everything in brackets will be calculated in reading order and not in sign priority. In cases where within the same parenthesis there will be a sum or subtraction and a division or multiplication and then the sign priority rule will apply. You can also use parentheses within parentheses for even more complex calculations.<\/p>\n<p>In addition to the 4 operators we know, there are 3 others that are very useful for our calculations.<\/p>\n<p>\\ (reverse split); using this operator will give the result only of the integer, eliminating the decimal part. Example: PRINT 18\\4, the result will be 4<br \/>\n^ (Exponentiation) Calculates the power of 2 numbers or variables. PRINT 2^3. Result will be 8.<br \/>\nMOD; Returns the remainder of an integer division. Taking the example above:<br \/>\nPRINT 18 MOD 4, the result is 2. To give a simple example to show one of the many ways to use it, I will print on the screen only the even numbers in a variable that will be increased by one number at a time.<\/p>\n<pre>10 A=0 20 A=A+1: IF A MOD 2 = 0 THEN PRINT A 30 GOTO 20<\/pre>\n<p>Although I haven&#039;t talked about the IF\/THEN conditioning function yet, the program is very simple to understand. I&#039;m saying that if the remainder is zero then the number is even so it has to print it, otherwise it&#039;s odd, because the remainder will be 1 and won&#039;t print.<\/p>\n<p>Relation operators compare 2 numbers or strings and return \u20131 if this is true, 0 if it is false. They are mainly used with IF\/THEN, in fact, you will understand better when I talk about the latter. For now let&#039;s understand what they are for.<\/p>\n<pre>Relation Operator = Equal &lt; Less &gt; Greater &lt;&gt; Different &lt;= Less equal &gt;= Greater equal<\/pre>\n<p>Logical operators are similar to relation operators, they compare 2 values that are true or false. These are also widely used with the IF\/THEN statement. They are: AND, OR, I will compare the 2 variables with the operators to show their results.<\/p>\n<p><img decoding=\"async\" class=\"lazyload\" data-src=\"https:\/\/scontent.fgoa5-2.fna.fbcdn.net\/v\/t39.30808-6\/365506474_199502643097019_8077328290955099294_n.jpg?_nc_cat=105&amp;ccb=1-7&amp;_nc_sid=5f2048&amp;_nc_ohc=wY53LeI7qp0AX9rcJSu&amp;_nc_ht=scontent.fgoa5-2.fna&amp;oh=00_AfBvaN8oKLkP2yDnYNxwpWLnUjzhuh6Ajppjt_0PDNxiFw&amp;oe=6560D88F\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"Potrebbe essere un'immagine raffigurante il seguente testo &quot;X XY XANDY XORY XEQVY 11 XIMPY IMP 1 XXORY 1 1 1 0 1 1 01 0 0 0 0 1 1 00 0 0 1 0 1 1 1 0&quot;\" \/><noscript><img decoding=\"async\" src=\"https:\/\/scontent.fgoa5-2.fna.fbcdn.net\/v\/t39.30808-6\/365506474_199502643097019_8077328290955099294_n.jpg?_nc_cat=105&amp;ccb=1-7&amp;_nc_sid=5f2048&amp;_nc_ohc=wY53LeI7qp0AX9rcJSu&amp;_nc_ht=scontent.fgoa5-2.fna&amp;oh=00_AfBvaN8oKLkP2yDnYNxwpWLnUjzhuh6Ajppjt_0PDNxiFw&amp;oe=6560D88F\" alt=\"Potrebbe essere un&#039;immagine raffigurante il seguente testo &quot;X XY XANDY XORY XEQVY 11 XIMPY IMP 1 XXORY 1 1 1 0 1 1 01 0 0 0 0 1 1 00 0 0 1 0 1 1 1 0&quot;\"><\/noscript><br \/>\nAND will be true only if the 2 results are true<br \/>\nOR will be true if 1 of the 2 or both results are true<br \/>\nEQV will only be true if they are both true or false<br \/>\nIMP will be true in all cases except when the former is true and the latter is false<br \/>\nXOR will be true only when one of the 2 is true.<br \/>\nNOT is the only unitary operator. It only operates on one topic, and is easy to understand. If it is false it becomes true and vice versa if it is true it becomes false.<\/p>\n<p>Before saying goodbye, I wanted to say that the column will be on holiday for a few weeks, we will see each other again at the beginning of September.<br \/>\nThanks again to everyone and see you soon.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>RUBRICA &#8220;MSX BASIC&#8221; a cura di Orazio Cacciola (parte 7) Operatori matematici, di relazione e logici Oggi parler\u00f2 dei vari operatori che sono fondamentali nei nostri programmi di Basic MSX. Gli operatori matematici, che tutti conosciamo e usiamo nella nostra vita quotidiana, come la somma (+), la sottrazione (-), la moltiplicazione (*) e la divisione [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[14],"tags":[],"dipi_cpt_category":[],"class_list":["post-5483","post","type-post","status-publish","format-standard","hentry","category-msx-basic"],"_links":{"self":[{"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/posts\/5483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/comments?post=5483"}],"version-history":[{"count":2,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/posts\/5483\/revisions"}],"predecessor-version":[{"id":5485,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/posts\/5483\/revisions\/5485"}],"wp:attachment":[{"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/media?parent=5483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/categories?post=5483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/tags?post=5483"},{"taxonomy":"dipi_cpt_category","embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/dipi_cpt_category?post=5483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}