diff --git a/ExtendedSystemObjects/ExtendedInt.cs b/ExtendedSystemObjects/ExtendedInt.cs index 061a836a..a7900d8c 100644 --- a/ExtendedSystemObjects/ExtendedInt.cs +++ b/ExtendedSystemObjects/ExtendedInt.cs @@ -8,6 +8,8 @@ // ReSharper disable UnusedMember.Global +using System; + namespace ExtendedSystemObjects { /// @@ -26,5 +28,51 @@ public static bool Interval(this int i, int value, int interval) { return i - interval <= value && value <= i + interval; } + + /// + /// Converts to binary. + /// + /// The i. + /// int as binary string + public static string ToBinary(this int i) + { + //2 is the new base, in our case binary, from decimal + return Convert.ToString(i, 2); + } + + /// + /// Binaries to int. + /// + /// The binary. + /// a binary string to decimal + public static int BinaryToInt(this string binary) + { + //2 was the base, convert back to decimal + return Convert.ToInt32(binary, 2); + } + + /// + /// Converts to base. + /// + /// The i. + /// To base. + /// int as target number string + public static string ToBase(this int i, int toBase) + { + //the toBase is the new base for our number system, from decimal + return Convert.ToString(i, toBase); + } + + /// + /// Binaries to base. + /// + /// The binary. + /// To base. + /// a binary string to target number system + public static int BinaryToBase(this string binary, int toBase) + { + //2 was the base, convert back to base + return Convert.ToInt32(binary, toBase); + } } }