Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
pluginbase.Helpers.Hex Class Reference

Hex computation helpers More...

Static Public Member Functions

static byte CharVal (char c)
 Convert a hex digit to its corresponding decimal digit More...
 
static byte CharValExpanded (char c)
 Convert a single hex digit, into its expanded 2-digit form Eg. Interpret 0xA as 0xAA More...
 
static byte CharVal (char c1, char c2)
 Gets the byte val of 2 hex digits More...
 
static int ToInt32 (string s)
 Convert a string sequence of Hex to its decimal form More...
 
static long ToInt64 (string s)
 Convert a string sequence of Hex digits to its decimal form More...
 
static string ToHex (long val, int minLen=0)
 Convert an integer to its hex string More...
 
static string ToHex (byte[] bytes)
 Convert an array of bytes to its hex string More...
 

Detailed Description

Hex computation helpers

Member Function Documentation

static byte pluginbase.Helpers.Hex.CharVal ( char  c)
static

Convert a hex digit to its corresponding decimal digit

Returns
The base10 digit.
Parameters
cC.

Attribute: c & 0xff

;

41  {
42  return _charValues[c & 0xff];
43  }
static byte pluginbase.Helpers.Hex.CharVal ( char  c1,
char  c2 
)
static

Gets the byte val of 2 hex digits

Returns
The decimal value.
Parameters
c1C1.
c2C2.

Attribute: c1 & 0xff] << 4 | _charValues[c2 & 0xff

);

64  {
65  return (byte)(_charValues[c1 & 0xff] << 4 | _charValues[c2 & 0xff]);
66  }
static byte pluginbase.Helpers.Hex.CharValExpanded ( char  c)
static

Convert a single hex digit, into its expanded 2-digit form Eg. Interpret 0xA as 0xAA

Returns
The decimal value
Parameters
cThe hex digit

Attribute: c & 0xff

;

52  {
53  byte v = _charValues[c & 0xff];
54  return (byte)(v << 4 | v);
55  }
static string pluginbase.Helpers.Hex.ToHex ( long  val,
int  minLen = 0 
)
static

Convert an integer to its hex string

Returns
The hex.
Parameters
valValue.
minLenMinimum length.

Attribute: val & 0xf

);

105  {
106  var s = new StringBuilder();
107  while(val > 0)
108  {
109  s.Insert(0, _valueSymbol[val & 0xf]);
110  val >>= 4;
111  }
112  while (s.Length < minLen)
113  s.Insert(0, '0');
114  return s.ToString();
115  }
static string pluginbase.Helpers.Hex.ToHex ( byte[]  bytes)
static

Convert an array of bytes to its hex string

Returns
The hex.
Parameters
bytesBytes.

Attribute: bytes[i] >> 4

); //Left bits

Attribute: bytes[i] & 0xf

); //Right bits

123  {
124  var s = new StringBuilder();
125  for (int i=0; i<bytes.Length; ++i)
126  {
127  s.Append(_valueSymbol[bytes[i] >> 4]); //Left bits
128  s.Append(_valueSymbol[bytes[i] & 0xf]); //Right bits
129  }
130  return s.ToString();
131  }
static int pluginbase.Helpers.Hex.ToInt32 ( string  s)
static

Convert a string sequence of Hex to its decimal form

Returns
Integer
Parameters
sHex string

Attribute: s[i] & 0xff

;

74  {
75  int v = 0;
76  for (int i=0; i<s.Length; ++i)
77  {
78  v = (v << 4) | _charValues[s[i] & 0xff];
79  }
80  return v;
81  }
static long pluginbase.Helpers.Hex.ToInt64 ( string  s)
static

Convert a string sequence of Hex digits to its decimal form

Returns
The int64.
Parameters
sHex string

Attribute: s[i] & 0xff

;

89  {
90  long v = 0;
91  for (int i=0; i<s.Length; ++i)
92  {
93  v = (v << 4) | _charValues[s[i] & 0xff];
94  }
95  return v;
96  }

The documentation for this class was generated from the following file: