From adebc5fa19d7cebf8dd1e7b8afa07f1b60a12e55 Mon Sep 17 00:00:00 2001 From: sschocke_cp <7f003704bc94ef3acf0afcda2bf5f827e6e21455CS9agd82> Date: Sun, 22 Mar 2009 13:27:23 +0000 Subject: [PATCH] Added UInt64 support to ToHex extensions, and also improved ConvertToHex methods for other numbers --- source/Cosmos/Cosmos.Kernel/Extension/Hex.cs | 28 +++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/source/Cosmos/Cosmos.Kernel/Extension/Hex.cs b/source/Cosmos/Cosmos.Kernel/Extension/Hex.cs index ffd9b6394..382306911 100644 --- a/source/Cosmos/Cosmos.Kernel/Extension/Hex.cs +++ b/source/Cosmos/Cosmos.Kernel/Extension/Hex.cs @@ -48,6 +48,16 @@ namespace Cosmos.Kernel { return ConvertToHex(aValue).PadLeft(aWidth, '0'); } + public static string ToHex(this ulong aValue) + { + return ConvertToHex(aValue); + } + + public static string ToHex(this ulong aValue, int aWidth) + { + return ConvertToHex(aValue).PadLeft(aWidth, '0'); + } + #endregion #region Prefix/Suffix @@ -70,14 +80,26 @@ namespace Cosmos.Kernel { { string xHex = string.Empty; - while (num >= 16) + while (num != 0) { //Note; char is converted to string because Cosmos crashes when adding char and string. Frode, 7.june. xHex = SingleDigitToHex((byte)(num & 0xf)).ToString() + xHex; - num = num / 16; + num = num >> 4; } - xHex = SingleDigitToHex((byte)(num & 0xf)).ToString() + xHex; + return xHex; + } + + private static string ConvertToHex(UInt64 num) + { + string xHex = string.Empty; + + while (num != 0) + { + //Note; char is converted to string because Cosmos crashes when adding char and string. Frode, 7.june. + xHex = SingleDigitToHex((byte)(num & 0xf)).ToString() + xHex; + num = num >> 4; + } return xHex; }