Library tutorials & articles
Number Systems
By Mitch Dusina, published on 16 Dec 2005
Page 1 of 5
- The Different Systems
- Any To Decimal
- Decimal To Any
- Any To Any
- Roman Numerals
The Different Systems
A Number System is simply a counting system. Each system has its own
base,
or number of unique symbols. The Decimal (Base 10) has 10 such
unique symbols (0-9). Binary has 2 (0 and 1). Any thing
above Base 10 uses a numeric and letter combination (such as
Hexadecimal's 0-9 A-F).
Here is a (not complete) list of Number Systems (The "no-name" entries are commonly refered to as: Base #):
Here is a (not complete) list of Number Systems (The "no-name" entries are commonly refered to as: Base #):
Public Enum NumeralSystems As Short
RomanNumerals = 0
Unary = 1
Binary = 2
Ternary = 3
Quaternary = 4
Quinary = 5
Senary = 6
Septenary = 7
Octal = 8
Novenary = 9
Undenary = 11
[Decimal] = 10
Duodecimal = 12
Tredecimal = 13
Quattuordecimal = 14
Quindecimal = 15
Hexadecimal = 16
Septendecimal = 17
Octodecimal = 18
Nonadecimal = 19
Vigesimal = 20
'
Quinquevigesimal = 25
Hexavigesimal = 26
Septemvigesimal = 27
'
Trigesimal = 30
'
Quadragesimal = 40
'
Quinquagesimal = 50
'
Sexagesimal = 60
'
Quattuorsexagesimal = 64
'
Septuagesimal = 70
'
Octagesimal = 80
'
Nonagesimal = 90
'
Centesimal = 100
'
Centivigesimal = 120
'
Bicentimal = 200
'
Tercentimal = 300
'
Quattrocentimal = 400
'
Quincentimal = 500
'
Millesimal = 1000
End Enum
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
It looks good, the only thing I can spot is the line where you catch the Exception. Not finding an extended numeral is expected (and common at that), so an Exception shouldn't be used to control the flow of code.
Although I can't think of an easy way around it since they removed Enum.TryParse (2.0 and later I think).
private int ParseRomanNumeral(string numeral)
{
numeral = numeral.ToUpper();
char[] characters = numeral.ToCharArray();
int[] parseBuf = new int[numeral.Length];
int result = 0;
bool bSkip = false;
for (int i = numeral.Length - 1; i >= 0; i--)
{
if (bSkip)
{
bSkip = false; // Skip this digit because it is part of a 2-digit numeral
continue;
}
parseBuf[i] = (int)Enum.Parse(typeof(RomanNumerals), characters[i].ToString());
if (parseBuf[i] % 5 == 0 && i > 0)
{
string extended = characters[i-1].ToString() + characters[i].ToString();
try
{
parseBuf[i] = (int)Enum.Parse(typeof(RomanNumerals), extended);
bSkip = true;
}
catch(ArgumentException)
{
// Ignore this exception. It just means we didn't find an extended numeral
}
}
}
for (int i = 0; i < numeral.Length; i++)
{
result += parseBuf[i];
}
return result;
}
private string ConvertToRomanNumeral(int num)
{
string sResult = "";
sResult = Enum.GetName(typeof(RomanNumerals), num);
if (sResult == null)
{
string[] names = Enum.GetNames(typeof(RomanNumerals));
int[] vals = (int[])Enum.GetValues(typeof(RomanNumerals));
for (int i = names.Length - 1; i > 0; i--) // Don't process the 0th element, since it is 0 and results in bad math
{
int temp = num / vals[i];
num -= temp * vals[i];
for (int j = 0; j < temp; j++)
{
sResult += names[i];
}
}
}
return sResult;
}
This thread is for discussions of Number Systems.