From 13d1f40f8502b18a05b9bf0e8ab63a0eeda3db66 Mon Sep 17 00:00:00 2001 From: Quajak Date: Mon, 19 Oct 2020 00:15:39 +0200 Subject: [PATCH 1/4] Added Ulong.ToString(string) Plug Allows default and hexadecimal outputs --- source/Cosmos.System2_Plugs/System/UInt64Impl.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/Cosmos.System2_Plugs/System/UInt64Impl.cs b/source/Cosmos.System2_Plugs/System/UInt64Impl.cs index b764ebcd6..a8c86b9b8 100644 --- a/source/Cosmos.System2_Plugs/System/UInt64Impl.cs +++ b/source/Cosmos.System2_Plugs/System/UInt64Impl.cs @@ -12,5 +12,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(); + } + } } } From 87d514f4be4d4c7afacaa0698cf9b5d8045d8db0 Mon Sep 17 00:00:00 2001 From: Quajak Date: Mon, 19 Oct 2020 00:18:09 +0200 Subject: [PATCH 2/4] Made 0 padding optional for ulong --- source/Cosmos.Common/Extensions/ToHexString.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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; + } } /// From b9d66e489d4b8f0ec11201a30254fd3ec8e0fd3e Mon Sep 17 00:00:00 2001 From: Quajak Date: Mon, 19 Oct 2020 00:21:38 +0200 Subject: [PATCH 3/4] Added tests for new option --- .../Cosmos.Compiler.Tests.Bcl.System/System/UInt64Test.cs | 2 ++ 1 file changed, 2 insertions(+) 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; From 418752aaf403c4754296c8fc50bef030db5549ba Mon Sep 17 00:00:00 2001 From: Quajak Date: Tue, 17 Nov 2020 10:05:23 +0100 Subject: [PATCH 4/4] Added missing using --- source/Cosmos.System2_Plugs/System/UInt64Impl.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/source/Cosmos.System2_Plugs/System/UInt64Impl.cs b/source/Cosmos.System2_Plugs/System/UInt64Impl.cs index a8c86b9b8..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;