diff --git a/Tests/Kernels/Cosmos.Compiler.Tests.Bcl.System/System/UInt64Test.cs b/Tests/Kernels/Cosmos.Compiler.Tests.Bcl.System/System/UInt64Test.cs index de0900af2..3b90380bc 100644 --- a/Tests/Kernels/Cosmos.Compiler.Tests.Bcl.System/System/UInt64Test.cs +++ b/Tests/Kernels/Cosmos.Compiler.Tests.Bcl.System/System/UInt64Test.cs @@ -18,6 +18,8 @@ namespace Cosmos.Compiler.Tests.Bcl.System expectedResult = "18446744073709551615"; Assert.IsTrue((result == expectedResult), "UInt64.ToString doesn't work"); + Assert.IsTrue(value.ToString("X") == "FFFFFFFFFFFFFFFF", "UInt64.ToString(X) doesn't work"); + Assert.IsTrue(((ulong)0x121411443).ToString("X") == "121411443", "UInt64.ToString(X) doesn't work"); // Now let's try to concat to a String using '+' operator result = "The Maximum value of an UInt64 is " + value; diff --git a/source/Cosmos.Common/Extensions/ToHexString.cs b/source/Cosmos.Common/Extensions/ToHexString.cs index 9703d1d9f..26a416309 100644 --- a/source/Cosmos.Common/Extensions/ToHexString.cs +++ b/source/Cosmos.Common/Extensions/ToHexString.cs @@ -112,13 +112,22 @@ } /// - /// Convert 64-bit unsigned int to 16 characters long hexadecimal string, padded with '0's. + /// Convert 64-bit unsigned int to 16 characters long hexadecimal string, optionally padded with '0's. /// /// A 64-bit unsigned int to be converted to hexadecimal string. - /// 16 characters long string value, padded with '0's. - public static string ToHex(this ulong aValue) + /// Determines if a left padding should be applied + /// 16 characters long string value, optionally padded with '0's. + public static string ToHex(this ulong aValue, bool withPadding = true) { - return ConvertToHex(aValue).PadLeft(16, '0'); + var hex = ConvertToHex(aValue); + if (withPadding) + { + return hex.PadLeft(16, '0'); + } + else + { + return hex; + } } /// diff --git a/source/Cosmos.System2_Plugs/System/UInt64Impl.cs b/source/Cosmos.System2_Plugs/System/UInt64Impl.cs index b764ebcd6..5bc7cacbe 100644 --- a/source/Cosmos.System2_Plugs/System/UInt64Impl.cs +++ b/source/Cosmos.System2_Plugs/System/UInt64Impl.cs @@ -1,5 +1,6 @@ using System; using Cosmos.Common; +using Cosmos.Common.Extensions; using IL2CPU.API; using IL2CPU.API.Attribs; @@ -12,5 +13,21 @@ namespace Cosmos.System_Plugs.System { return StringHelper.GetNumberString(aThis); } + + public static string ToString(ref ulong aThis, string formating) + { + if(formating == "X") + { + return ToHexString.ToHex(aThis, false); + } + else if(formating == "G") + { + return ToString(ref aThis); + } + else + { + throw new NotImplementedException(); + } + } } }