{"id":37210,"date":"2023-02-26T11:49:36","date_gmt":"2023-02-26T10:49:36","guid":{"rendered":"https:\/\/hooxies.nl\/?page_id=37210"},"modified":"2026-11-25T21:08:32","modified_gmt":"2026-11-25T20:08:32","slug":"roman","status":"publish","type":"page","link":"https:\/\/hooxies.nl\/?page_id=37210","title":{"rendered":"ROMAN"},"content":{"rendered":"<p><b>Display<\/b><br \/>\n<a rel=\"hp41cxroman\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-hp41cx.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-hp41cx.png\" alt=\"\" width=\"227\" height=\"104\" \/><\/a> <a rel=\"hp41cxroman\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-dm41x.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-dm41x.png\" alt=\"\" width=\"173\" height=\"104\"  \/><\/a><br \/>\n<em>(HP-41CX, Hewlett Packard 1983 and DM41X, <a href=\"https:\/\/www.swissmicros.com\/\" rel=\"noopener noreferrer\" target=\"_blank\">SwissMicros<\/a> 2020)<\/em><br \/>\n&nbsp;<\/p>\n<p><b>Overview<\/b><br \/>\nPrograms <tt>R2N<\/tt> (and <tt>R3N<\/tt>) and <tt>N2R<\/tt> convert decimal (Arabic) numbers to Roman notation and vice versa. The number conversion goes from 1-3999.<br \/>\nMany conversion programs have been created by several users aiming to build with the least number of  bytes for the programs. The programs in this document require HP-41CX functions XTOA and ATOX. The main difficulty with the conversion to and from Roman numbers is the so-called subtractive rule. To convert numbers correctly the conversion rules are to be followed precisely. Here is a short summary. Roman numerals are written using seven different letters: I, V, X, L, C, D and M, they represent the numbers 1, 5, 10, 50, 100, 500 and 1,000. The use these seven letters makes up thousands of others. For example, the Roman numeral for 2 is written as \u2018II&#8217; which is just two 1&#8217;s smushed together. The number 12 is XII which is just X (10) + II (2). Taking it a step further, the number 27 is written as XXVII, which when broken down looks like XX (20) + V (5) + II (2); all totaled up it equals to 27.<br \/>\nRoman numerals are usually written largest to smallest from left to right. However, this is not always true. The Romans didn&#8217;t like writing four of the same numerals in a row, so they developed a system of subtraction.<br \/>\nThe Roman numeral for 3 is written III, but 4 is not IIII. Instead, the subtractive principle is used. The number 4 is written as &#8216;IV&#8217;. It shows the I (1) before V (5) and because the smaller number is before the larger number, it must be subtracted here \u2013 giving the value 4 for  IV. The same principle applies to the number 9, which is written as IX.<br \/>\nThere are six instances where subtraction is used:<\/p>\n<ul>\n<li>I can be placed before V (5) and X (10) to make 4 and 9.<\/li>\n<li>X can be placed before L (50) and C (100) to make 40 and 90.<\/li>\n<li>C can be placed before D (500) and M (1000) to make 400 and 900.<\/li>\n<\/ul>\n<p>The number 994 is a great example of this rule \u2013 it&#8217;s written CMXCIV. Broken down we have CM = 900, XC = 90 and IV = 4; adding all these up results in 994.<br \/>\nThe solution approach to code the algorithm is from Sriharsha Sammeta as described in: <a href=\"https:\/\/www.geeksforgeeks.org\/converting-decimal-number-lying-between-1-to-3999-to-roman-numerals\/amp\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.geeksforgeeks.org\/converting-decimal-number-lying-between-1-to-3999-to-roman-numerals\/amp\/<\/a>.<br \/>\n&nbsp;<\/p>\n<p><b>Conversion<\/b><br \/>\nThe solution approach follows the algorithm in which the normal and subtractive rules are implemented in a straightforward manner. In this approach the <b>MainSignificantDigit<\/b> in the number is considered first. For example, in 1234, the main significant digit is 1. Similarly in 345 it is 3.<br \/>\nTo extract the main significant digit out, a divisor (div) like 1000 for 1234 (since 1234 \/ 1000 = 1) is required which is 100 in the case of 345 is 3 (345 \/ 100).<br \/>\nA lookup called <b>RomanNumeral<\/b> is defined as =<br \/> {1 : \u2018I\u2019, 5: \u2018V\u2019, 10: \u2018X\u2019, 50: \u2018L\u2019, 100: \u2018C\u2019, 500: \u2018D\u2019, 1000: \u2018M\u2019}<br \/>\nFor each digit in the decimal number, the following logic applies (in which <b>div<\/b> refers to the Roman base):<br \/>\n<code style=\"font-size: 12px;\"><br \/>\n&nbsp;&nbsp;if <b>MainSignificantDigit<\/b> <= 3<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>RomanNumeral<\/b> [div] * <b>MainSignificantDigit<\/b><br \/>\n&nbsp;&nbsp;if <b>MainSignificantDigit<\/b> == 4<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>RomanNumeral [div] + <\/b><b>RomanNumeral<\/b> [div*5]<br \/>\n&nbsp;&nbsp;if 5 <= <b>MainSignificantDigit<\/b> <= 8<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>RomanNumeral<\/b> [div*5] + (<b>RomanNumeral<\/b> [div] * (<b>MainSignificantDigit<\/b>-5))<br \/>\n&nbsp;&nbsp;if MainSignificantDigit == 9<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>RomanNumeral<\/b> [div] + <b>RomanNumeral<\/b> [div*10]<br \/>\n<\/code><\/p>\n<p>Here is an example: suppose the input number is 3984:<br \/>\nIteration 1: &nbsp;&nbsp;Initial number = 3984<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MainSignificantDigit is 3; div = 1000. RomanNumeral [1000] * 3 gives: MMM<br \/>\nIteration 2:&nbsp;&nbsp;Updated number = 984<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MainSignificantDigit is 9; div = 100.<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RomanNumeral [100] + RomanNumeral [100*10] gives: CM<br \/>\nIteration 3:&nbsp;&nbsp;Updated number = 84<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MainSignificantDigit is 8; div = 10.<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RomanNumeral [10*5] + RomanNumeral [10]*(8-5) gives: LXXX<br \/>\nIteration 4:&nbsp;&nbsp;Updated number = 4<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MainSignificantDigit is 4; div = 1.<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RomanNumeral [1] + RomanNumeral [10*5] gives: IV.<\/p>\n<p>The result by clubbing all the above gives MMMCMLXXXIV for the number 3984.<br \/>\n&nbsp;<\/p>\n<p><b>Examples (1): N2R<\/b><br \/>\n<a rel=\"hp41cxroman\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-example1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-example1-413x76.png\" alt=\"\" width=\"413\" height=\"76\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Examples (2): R2N<\/b><br \/>Please note that my default <tt>FIX 5<\/tt> setting which can be replaced by your preferred number of decimals.<br \/>\n<a rel=\"hp41cxroman\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-example2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-example2-413x90.png\" alt=\"\" width=\"413\" height=\"90\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Program Listing<\/b><br \/>\nThe listing of programs N2R (Numerical to Roman) is given below:<br \/>\n<a rel=\"hp41cxroman\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-program-n2r.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-program-n2r-413x276.png\" alt=\"\" width=\"413\" height=\"276\"  \/><\/a><\/p>\n<p>and for R2N  (Roman to Numerical) shown here:<br \/>\n<a rel=\"hp41cxroman\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-program-r2n.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-program-r2n-413x211.png\" alt=\"\" width=\"413\" height=\"211\"  \/><\/a><\/p>\n<p>The alternative of R2N  is listed as R3N  (with hard coded initialisation):<br \/>\n<a rel=\"hp41cxroman\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-program-r3n.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-program-r3n-413x189.png\" alt=\"\" width=\"413\" height=\"189\"  \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Registers, Labels and Flags<\/b><br \/>\n<a rel=\"hp41cxroman\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-registers.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman-registers-413x242.png\" alt=\"\" width=\"413\" height=\"242\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Downloads<\/b><br \/>\nPDF format of programs <a rel=\"hp41cxroman\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman.pdf\">N2R, R2N and R3N<\/a>.<br \/>\nRAW\/TXT format of programs <a href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/roman.zip\">N2R, R2N and R3N<\/a> (in zip file).<br \/>\n&nbsp;<\/p>\n<div style=\"font-size: 12px;\">This program is copyright and is supplied without representation or warranty of any kind. The author assumes no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof<\/div>\n<p><i>&copy; 1999-2023 by Auke Hoekstra<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Display (HP-41CX, Hewlett Packard 1983 and DM41X, SwissMicros 2020) &nbsp; Overview Programs R2N (and R3N) and N2R convert decimal (Arabic) numbers to Roman notation and vice versa. The number conversion goes from 1-3999. Many conversion programs have been created by several users aiming to build with the least number of bytes for the programs. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_oct_exclude_from_cache":false,"footnotes":""},"class_list":["post-37210","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/37210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hooxies.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=37210"}],"version-history":[{"count":1,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/37210\/revisions"}],"predecessor-version":[{"id":57407,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/37210\/revisions\/57407"}],"up":[{"embeddable":true,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/2"}],"wp:attachment":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=37210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}