Usless but maybe fun excercise

ndzied1

Lifetime Supporting Member
Join Date
Aug 2002
Location
Chicago, Illinois
Posts
2,854
At breakfast this morning, my son started talking about Roman Numerals. Of course, my mind quickly wondered to how to write a PLC program to display the year, or time or any number in Roman Numerals on an HMI. Of course this is very platform dependant but issues of displaying strings have been coming up lately and I thought I'd throw it out there for the masses.
 
In a PLC? Interesting. One of my first programs I wrote on my first home comuputer (TRS-80) in BASIC was to input a string, determine if it was Roman Numeral, Arabic Numerals or something else, then, if one of the number formats, convert and output it as the other. A great learning experience.
 
Actually, the only difference between Roman and decimal systems is the floating radix of the Roman system.

The decimal-to-Roman algorythm is not difficult and also not that useless.
The examples immediately coming in mind are:
- Composing necessary money amount from different value coins and/or bills.
- Weighing and all it's variations, including analog-to-digital conversion in electronics.
 
There is also the question of which mode of conversion is to be used. The Romans on their buildings most often used the purely additive form (9 = VIIII) while we now tend to see the subtractive form for avoiding more than 3 occurances of a symbol (9 = IX).
 
Yes, but this is just a simple additional procedure applying to four consecutive similar symbols.
It may be considered an illegal combination of legal symbols, something like nibbles with values over 9 in BCD.
I would probably program additive-to-subtractive conversion as a second step of the conversion.
BTW, in the subtractive form symbols change their radix to negative when they are positioned before more valuable symbol, that is floating radix.
In the additive form the radix is not floating, it is just non-proportional.
 
Last edited:

Assuming the number is limited to 9,999 (and neglecting the Bar-V for 5000)

String = Null

Number / 1000 = Result

If Result > 0 Then...
- Append "Result" Ms (For example, if Result = 3, Append three Ms)
- Number - (Result x 1000) = Number
EndIf

If Number >= 900 Then...
- Append "CM"
- Number - 900 = Number
ElseIf Number >= 500 Then...
- Append "D"
- Number - 500 = Number
ElseIf Number >= 400 Then...
- Append "CD"
- Number - 400 = Number
EndIf

Number / 100 = Result

If Result > 0 Then...
- Append "Result" Cs (For example, if Result = 3, Append three Cs)
- Number - (Result x 100) = Number
EndIf

If Number >= 90 Then...
- Append "XC"
- Number - 90 = Number
ElseIf Number >= 50 Then...
- Append "L"
- Number - 50 = Number
ElseIf Number >= 40 Then...
- Append "XL"
- Number - 40 = Number
EndIf

Number / 10 = Result

If Result > 0 Then...
- Append "Result" Xs (For example, if Result = 3, Append three Xs)
- Number - (Result x 10) = Number
EndIf

If Number = 9 Then...
- Append "IX"
ElseIf Number >= 5 Then...
- Append "V"
- Number - 5 = Number
ElseIf Number = 4 Then...
- Append "IV"
- Number - 4 = Number
EndIf

Append "Number" Is (For example, if Number = 3, Append three Is)

 
well... somehow like this... assume floor round and non-float division

no/1000 = m_count; no -= m_count*1000;
no/500 = d_count; no -= d_count*500;
no/100 = c_count; no -= c_count*100;
no/50 = l_count; no -= l_count*50;
no/10 = x_count; no -= x_count*10;

now we need to assemble string m_count*'M'+d_count*'D'+ .... + no*'I'
yes, just original, not classical mode
 

Similar Topics

Hello folks! Never been here before but I have a question that's been bugging me for a while. I recently got a job at a chemical plant that's...
Replies
8
Views
327
Hello! The equipment I'm working on uses a lot of indexed tags I guess you'd call them. I thought it was indirect addresses maybe but all the...
Replies
9
Views
1,029
Hello all. I have 5 PF525's in my RSL5k project. One such drive I am able to ping and it responds. The Enet on the front is steady green and the...
Replies
5
Views
2,826
I have come across a situation that could be in need of help. Presently, they have an L71 running version 24.12, and they want to revise it...
Replies
3
Views
1,326
Hello, I've had a 1746-NT8 thermocouple input card fail on an SLC5/05 unit. There is another TC card in this rack that has spare input channels...
Replies
4
Views
1,632
Back
Top Bottom