Class ToHexString
Contains various helper methods to convert ints to hex represented by string. Supported types:
- byte.
- ushort.
- int.
- uint.
- ulong.
Inheritance
Inherited Members
Namespace: Cosmos.Common.Extensions
Assembly: Cosmos.Common.dll
Syntax
public static class ToHexString
Methods
| Improve this Doc View SourceDigitToHexChar(Byte)
Convert byte to hexadecimal char.
Declaration
public static char DigitToHexChar(byte d)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | d | A byte to be converted to hexadecimal char. |
Returns
Type | Description |
---|---|
System.Char | Char value. |
ToHex(Byte)
Convert byte to 2 characters long hexadecimal string, padded with '0's.
Declaration
public static string ToHex(this byte n)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | n | A byte to be converted to hexadecimal string. |
Returns
Type | Description |
---|---|
System.String | 2 characters long string value, padded with '0's. |
ToHex(Byte, Int32)
Convert byte to hexadecimal string of a given length.
Declaration
public static string ToHex(this byte n, int aWidth)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | n | A byte to be converted to hexadecimal string. |
System.Int32 | aWidth | The number of characters in the resulting string. |
Returns
Type | Description |
---|---|
System.String | String value, right aligned and padded on the left with '0's. If aWidth is less then the length of the resulting string, the resulting string would not be trimmed. |
ToHex(Int32)
Convert int to 4 characters long hexadecimal string, padded with '0's.
Declaration
public static string ToHex(this int n)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | A int to be converted to hexadecimal string. |
Returns
Type | Description |
---|---|
System.String | 4 characters long string value, padded with '0's. |
ToHex(Int32, Int32)
Convert int to hexadecimal string of a given length.
Declaration
public static string ToHex(this int n, int aWidth)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | A int to be converted to hexadecimal string. |
System.Int32 | aWidth | The number of characters in the resulting string. |
Returns
Type | Description |
---|---|
System.String | String value, right aligned and padded on the left with '0's. If aWidth is less then the length of the resulting string, the resulting string would not be trimmed. |
ToHex(UInt16)
Convert 16-bit unsigned int to 4 characters long hexadecimal string, padded with '0's.
Declaration
public static string ToHex(this ushort n)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | n | A 16-bit unsigned int to be converted to hexadecimal string. |
Returns
Type | Description |
---|---|
System.String | 4 characters long string value, padded with '0's. |
ToHex(UInt16, Int32)
Convert 16-bit unsigned int to hexadecimal string of a given length.
Declaration
public static string ToHex(this ushort n, int aWidth)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | n | A 16-bit unsigned int to be converted to hexadecimal string. |
System.Int32 | aWidth | The number of characters in the resulting string. |
Returns
Type | Description |
---|---|
System.String | String value, right aligned and padded on the left with '0's. If aWidth is less then the length of the resulting string, the resulting string would not be trimmed. |
ToHex(UInt32)
Convert 32-bit unsigned int to 8 characters long hexadecimal string, padded with '0's.
Declaration
public static string ToHex(this uint aValue)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | aValue | A 32-bit unsigned int to be converted to hexadecimal string. |
Returns
Type | Description |
---|---|
System.String | 8 characters long string value, padded with '0's. |
ToHex(UInt32, Int32)
Convert 32-bit unsigned int to hexadecimal string of a given length.
Declaration
public static string ToHex(this uint aValue, int aWidth)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | aValue | A 32-bit unsigned int to be converted to hexadecimal string. |
System.Int32 | aWidth | The number of characters in the resulting string. |
Returns
Type | Description |
---|---|
System.String | String value, right aligned and padded on the left with '0's. If aWidth is less then the length of the resulting string, the resulting string would not be trimmed. |
ToHex(UInt64, Boolean)
Convert 64-bit unsigned int to 16 characters long hexadecimal string, optionally padded with '0's.
Declaration
public static string ToHex(this ulong aValue, bool withPadding = true)
Parameters
Type | Name | Description |
---|---|---|
System.UInt64 | aValue | A 64-bit unsigned int to be converted to hexadecimal string. |
System.Boolean | withPadding | Determines if a left padding should be applied |
Returns
Type | Description |
---|---|
System.String | 16 characters long string value, optionally padded with '0's. |
ToHex(UInt64, Int32)
Convert 64-bit unsigned int to hexadecimal string of a given length.
Declaration
public static string ToHex(this ulong aValue, int aWidth)
Parameters
Type | Name | Description |
---|---|---|
System.UInt64 | aValue | A 64-bit unsigned int to be converted to hexadecimal string. |
System.Int32 | aWidth | The number of characters in the resulting string. |
Returns
Type | Description |
---|---|
System.String | String value, right aligned and padded on the left with '0's. If aWidth is less then the length of the resulting string, the resulting string would not be trimmed. |