Parallel Plane Sweep  0.1
Shared memory multithreaded version of the plane sweep algorithm
d2hex.h
Go to the documentation of this file.
1 /*
2  * The MIT License (MIT)
3  * Copyright (c) <2016> <Mark McKenney>
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6  *
7  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10  * */
11 
12 #include <iostream>
13 #include <string>
14 #include <cstring>
15 using namespace std;
16 
17 #ifndef D2HEX_H
18 #define D2HEX_H
19 
31 {
32  public:
42  static double hex2d( const string & hexer )
43  {
44  long long int d = 0;
45  int theBits;
46  double result;
47  for( int i = 0; i< hexer.size(); i++)
48  {
49  // convert the hex digit to a number
50  theBits = hexDigit2dec( hexer[i] );
51  //cout << "the num: " << theBits << endl;
52  d = d<<4;
53  d = d | theBits;
54  }
55 
56  memcpy( &result, &d, sizeof( long long int ) );
57  return result;
58  }
59 
68  static string d2hex( const double d )
69  {
70  string hexer;
71  char *theChars;
72  unsigned int bits;
73  char mask = 0x01;
74  hexer = "";
75  //memcpy( theChars, &test, sizeof( int ) );
76  theChars = (char*)(void*)&d;
77  for( unsigned int i = 0; i < sizeof( double ); i++ )
78  {
79 
80  bits = 0;
81  // get a char, extract the first 4 bits
82  for( unsigned int j = 0; j < 4; j++ )
83  {
84  bits |= ((theChars[i] >> j) & mask) << j;
85  }
86  hexer = dec2hexDigit(bits)+hexer;
87  bits = 0;
88  for( unsigned int j = 4; j < 8; j++ )
89  {
90  bits |= ((theChars[i] >> j) & mask) << j-4;
91  }
92  hexer = dec2hexDigit(bits)+hexer;
93  }
94  //cout << hexer << endl;
95  return hexer;
96  }
97 
104  static unsigned int hexDigit2dec( const char hexDigit )
105  {
106  unsigned int decDigit = (int)hexDigit - (int)'0' ;
107  if( decDigit > 9 )
108  decDigit = (int)hexDigit - (int)'a' + 10;
109  return decDigit;
110  }
117  static char dec2hexDigit( const unsigned int decDigit )
118  {
119  if( decDigit < 10 )
120  return (char)( decDigit + (int)'0');
121  else
122  return (char)( (decDigit-10)+(int)'a');
123  }
124 
125 };
126 
127 #endif
128 
129 
130 
static unsigned int hexDigit2dec(const char hexDigit)
Definition: d2hex.h:104
static char dec2hexDigit(const unsigned int decDigit)
Definition: d2hex.h:117
convert double numbers to hex strings and vice versa
Definition: d2hex.h:30
static string d2hex(const double d)
Definition: d2hex.h:68
static double hex2d(const string &hexer)
Definition: d2hex.h:42