41 using std::stringstream;
99 struct {
int w1;
int w2;} s;
105 std::string result =
"";
107 for (
unsigned int i = 0; i <
sizeof(int) * 8; i++) {
109 if ((cast.s.w1 & 0x80000000) != 0) {
117 for (
unsigned int i = 0; i <
sizeof(int) * 8; i++) {
119 if ((cast.s.w2 & 0x80000000) != 0) {
127 string::size_type firstOne = result.find(
"1");
129 if (firstOne != string::npos) {
130 result = result.substr(firstOne, string::npos);
157 std::string result =
"";
158 for (
unsigned int i = 0; i <
sizeof(
unsigned int) * 8; i++) {
160 if ((source & 0x80000000) != 0) {
168 if (stringWidth == 0) {
169 string::size_type firstOne = result.find(
"1");
170 if (firstOne != string::npos) {
171 result = result.substr(firstOne, string::npos);
176 if (result.length() > stringWidth) {
177 result = result.substr(
178 result.length() - stringWidth, string::npos);
179 }
else if (result.length() < stringWidth) {
180 int zerosToAdd = stringWidth - result.length();
181 for (
int i = 0; i < zerosToAdd; i++) {
182 result.insert(0,
"0");
202 std::string hexValue = hexSource;
203 std::stringstream hexStream;
204 hexStream << hexSource;
205 char first = hexStream.get();
206 char second = hexStream.get();
208 if (first ==
'0' && second ==
'x') {
209 hexValue = hexSource.substr(2);
214 if (hexValue.size() % 2 == 1) {
215 hexValue.insert(0,
"0");
220 for (
size_t i = 0; i < hexValue.size(); i=i+2) {
221 *target =
toInt(
"0x" + hexValue.substr(i, 2));
232 float source,
bool include0x) {
241 std::stringstream str;
242 str << std::setw(8) << std::setfill(
'0') << std::right << std::hex
245 std::string result =
"";
249 result.insert(0,
"0x");
262 unsigned char* bytes = (
unsigned char*) &source;
263 std::stringstream str;
267 for (
size_t i = 0; i <
sizeof(double); i++) {
268 #if HOST_BIGENDIAN == 1
269 unsigned int value = (
unsigned int)bytes[i];
271 unsigned int value = (
unsigned int)bytes[
sizeof(
double)-i-1];
274 str << std::setfill(
'0') << std::setw(2) << std::hex << value;
276 return std::string(str.str());