ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
Hex.cpp
Go to the documentation of this file.
1 
53 
54 using namespace etiss::plugin::gdb::hex;
55 
57 {
58  if (c <= '9' && c >= '0')
59  {
60  return (uint8_t)(c - '0');
61  }
62  else if (c <= 'f' && c >= 'a')
63  {
64  return (uint8_t)(c - 'a' + 10);
65  }
66  else if (c <= 'F' && c >= 'A')
67  {
68  return (uint8_t)(c - 'A' + 10);
69  }
70  else
71  {
72  return 16;
73  }
74 }
76 {
77  if (l < 10)
78  {
79  return '0' + (char)l;
80  }
81  else if (l < 16)
82  {
83  return 'A' + (char)l - 10;
84  }
85  else
86  {
87  return '?';
88  }
89 }
90 
91 uint8_t etiss::plugin::gdb::hex::toByte(std::string hex, size_t pos)
92 {
93  return toByte(hex[pos], hex[pos + 1]);
94 }
96 {
97  return fromHex(h) << 4 | fromHex(l);
98 }
99 
101 {
102  std::string ret = " ";
103  ret[0] = toHex(byte >> 4);
104  ret[1] = toHex(byte & 0x0F);
105  return ret;
106 }
107 
108 void etiss::plugin::gdb::hex::fromByte(std::string &append, uint8_t byte)
109 {
110  append.push_back(toHex(byte >> 4));
111  append.push_back(toHex(byte & 0x0F));
112 }
113 
115 {
116  std::string ret;
117  ret.resize(length * 2);
118  for (unsigned i = 0; i < length; i++)
119  {
120  ret[i * 2] = toHex(buf[i] >> 4);
121  ret[i * 2 + 1] = toHex(buf[i] & 0x0F);
122  }
123  return ret;
124 }
__device__ __2f16 float c
static __inline__ uint8_t
Definition: arm_mve.h:323
uint8_t toByte(char h, char l)
converts 2 hex characters to a byte
Definition: Hex.cpp:95
std::string fromByte(uint8_t byte)
converts a byte to a hex string (without "0x" prefix);
Definition: Hex.cpp:100
std::string fromBytes(uint8_t *buf, size_t length)
converts a sequence of bytes to a representing hex string (without "0x" prefix)
Definition: Hex.cpp:114
uint8_t fromHex(char c)
convert a character to the hex value it represents(0-15)
Definition: Hex.cpp:56
char toHex(uint8_t l)
converts the lower 4 bits to a representing char
Definition: Hex.cpp:75
float __ovld __cnfn length(float p)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)