Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reflection.Metadata.Ecma335;
- namespace NumeralSystems
- {
- /// <summary>
- /// Converts a string representations of a numbers to its integer equivalent.
- /// </summary>
- public static class Converter
- {
- /// <summary>
- /// Converts the string representation of a positive number in the octal numeral system to its 32-bit signed integer equivalent.
- /// </summary>
- /// <param name="source">The string representation of a positive number in the octal numeral system.</param>
- /// <returns>A positive decimal value.</returns>
- /// <exception cref="ArgumentException">
- /// Thrown if source string presents a negative number
- /// - or
- /// contains invalid symbols (non-octal alphabetic characters).
- /// Valid octal alphabetic characters: 0,1,2,3,4,5,6,7.
- /// </exception>
- public static int ParsePositiveFromOctal(this string source) => throw new NotImplementedException();
- /// <summary>
- /// Converts the string representation of a positive number in the decimal numeral system to its 32-bit signed integer equivalent.
- /// </summary>
- /// <param name="source">The string representation of a positive number in the decimal numeral system.</param>
- /// <returns>A positive decimal value.</returns>
- /// <exception cref="ArgumentException">
- /// Thrown if source string presents a negative number
- /// - or
- /// contains invalid symbols (non-decimal alphabetic characters).
- /// Valid decimal alphabetic characters: 0,1,2,3,4,5,6,7,8,9.
- /// </exception>
- public static int ParsePositiveFromDecimal(this string source) => throw new NotImplementedException();
- /// <summary>
- /// Converts the string representation of a positive number in the hex numeral system to its 32-bit signed integer equivalent.
- /// </summary>
- /// <param name="source">The string representation of a positive number in the hex numeral system.</param>
- /// <returns>A positive decimal value.</returns>
- /// <exception cref="ArgumentException">
- /// Thrown if source string presents a negative number
- /// - or
- /// contains invalid symbols (non-hex alphabetic characters).
- /// Valid hex alphabetic characters: 0,1,2,3,4,5,6,7,8,9,A(or a),B(or b),C(or c),D(or d),E(or e),F(or f).
- /// </exception>
- public static int ParsePositiveFromHex(this string source) => throw new NotImplementedException();
- /// <summary>
- /// Converts the string representation of a positive number in the octal, decimal or hex numeral system to its 32-bit signed integer equivalent.
- /// </summary>
- /// <param name="source">The string representation of a positive number in the the octal, decimal or hex numeral system.</param>
- /// <param name="radix">The radix.</param>
- /// <returns>A positive decimal value.</returns>
- /// <exception cref="ArgumentException">
- /// Thrown if source string presents a negative number
- /// - or
- /// contains invalid for given numeral system symbols
- /// -or-
- /// the radix is not equal 8, 10 or 16.
- /// </exception>
- public static int ParsePositiveByRadix(this string source, int radix) => throw new NotImplementedException();
- /// <summary>
- /// Converts the string representation of a signed number in the octal, decimal or hex numeral system to its 32-bit signed integer equivalent.
- /// </summary>
- /// <param name="source">The string representation of a signed number in the the octal, decimal or hex numeral system.</param>
- /// <param name="radix">The radix.</param>
- /// <returns>A signed decimal value.</returns>
- /// <exception cref="ArgumentException">
- /// Thrown if source contains invalid for given numeral system symbols
- /// -or-
- /// the radix is not equal 8, 10 or 16.
- /// </exception>
- public static int ParseByRadix(this string source, int radix)
- {
- int pow = 1;
- int result = 0;
- int buffer = 0;
- for (int i = source.Length - 1; i >= 0; i--)
- {
- buffer = source[i] switch
- {
- '0' => 0,
- '1' => 1,
- '2' => 2,
- '3' => 3,
- '4' => 4,
- '5' => 5,
- '6' => 6,
- '7' => 7,
- '8' => 8,
- '9' => 9,
- 'A' => 10,
- 'B' => 11,
- 'C' => 12,
- 'D' => 13,
- 'E' => 14,
- 'F' => 15,
- _ => 0
- };
- result += buffer * pow;
- pow *= radix;
- }
- return source[0] == '-' ? -result : result;
- }
- /// <summary>
- /// Converts the string representation of a positive number in the octal numeral system to its 32-bit signed integer equivalent.
- /// A return value indicates whether the conversion succeeded.
- /// </summary>
- /// <param name="source">The string representation of a positive number in the octal numeral system.</param>
- /// <param name="value">A positive decimal value.</param>
- /// <returns>true if s was converted successfully; otherwise, false.</returns>
- public static bool TryParsePositiveFromOctal(this string source, out int value) => throw new NotImplementedException();
- /// <summary>
- /// Converts the string representation of a positive number in the decimal numeral system to its 32-bit signed integer equivalent.
- /// A return value indicates whether the conversion succeeded.
- /// </summary>
- /// <param name="source">The string representation of a positive number in the decimal numeral system.</param>
- /// <returns>A positive decimal value.</returns>
- /// <param name="value">A positive decimal value.</param>
- /// <returns>true if s was converted successfully; otherwise, false.</returns>
- public static bool TryParsePositiveFromDecimal(this string source, out int value) => throw new NotImplementedException();
- /// <summary>
- /// Converts the string representation of a positive number in the hex numeral system to its 32-bit signed integer equivalent.
- /// A return value indicates whether the conversion succeeded.
- /// </summary>
- /// <param name="source">The string representation of a positive number in the hex numeral system.</param>
- /// <returns>A positive decimal value.</returns>
- /// <param name="value">A positive decimal value.</param>
- /// <returns>true if s was converted successfully; otherwise, false.</returns>
- public static bool TryParsePositiveFromHex(this string source, out int value) => throw new NotImplementedException();
- /// <summary>
- /// Converts the string representation of a positive number in the octal, decimal or hex numeral system to its 32-bit signed integer equivalent.
- /// A return value indicates whether the conversion succeeded.
- /// </summary>
- /// <param name="source">The string representation of a positive number in the the octal, decimal or hex numeral system.</param>
- /// <param name="radix">The radix.</param>
- /// <returns>A positive decimal value.</returns>
- /// <param name="value">A positive decimal value.</param>
- /// <returns>true if s was converted successfully; otherwise, false.</returns>
- /// <exception cref="ArgumentException">Thrown the radix is not equal 8, 10 or 16.</exception>
- public static bool TryParsePositiveByRadix(this string source, int radix, out int value) => throw new NotImplementedException();
- /// <summary>
- /// Converts the string representation of a signed number in the octal, decimal or hex numeral system to its 32-bit signed integer equivalent.
- /// A return value indicates whether the conversion succeeded.
- /// </summary>
- /// <param name="source">The string representation of a signed number in the the octal, decimal or hex numeral system.</param>
- /// <param name="radix">The radix.</param>
- /// <returns>A positive decimal value.</returns>
- /// <param name="value">A positive decimal value.</param>
- /// <returns>true if s was converted successfully; otherwise, false.</returns>
- /// <exception cref="ArgumentException">Thrown the radix is not equal 8, 10 or 16.</exception>
- public static bool TryParseByRadix(this string source, int radix, out int value) =>
- throw new NotImplementedException();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement