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 
13 #include <iostream>
14 #include <string>
15 #include <cstring>
16 using namespace std;
17 
18 #ifndef D2HEX_H
19 #define D2HEX_H
20 
32 {
33  public:
43  static double hex2d( const string & hexer )
44  {
45  long long int d = 0;
46  int theBits;
47  double result;
48  for( int i = 0; i< hexer.size(); i++)
49  {
50  // convert the hex digit to a number
51  theBits = hexDigit2dec( hexer[i] );
52  //cout << "the num: " << theBits << endl;
53  d = d<<4;
54  d = d | theBits;
55  }
56 
57  memcpy( &result, &d, sizeof( long long int ) );
58  return result;
59  }
60 
69  static string d2hex( const double d )
70  {
71  string hexer;
72  char *theChars;
73  unsigned int bits;
74  char mask = 0x01;
75  hexer = "";
76  //memcpy( theChars, &test, sizeof( int ) );
77  theChars = (char*)(void*)&d;
78  for( unsigned int i = 0; i < sizeof( double ); i++ )
79  {
80 
81  bits = 0;
82  // get a char, extract the first 4 bits
83  for( unsigned int j = 0; j < 4; j++ )
84  {
85  bits |= ((theChars[i] >> j) & mask) << j;
86  }
87  hexer = dec2hexDigit(bits)+hexer;
88  bits = 0;
89  for( unsigned int j = 4; j < 8; j++ )
90  {
91  bits |= ((theChars[i] >> j) & mask) << j-4;
92  }
93  hexer = dec2hexDigit(bits)+hexer;
94  }
95  //cout << hexer << endl;
96  return hexer;
97  }
98 
105  static unsigned int hexDigit2dec( const char hexDigit )
106  {
107  unsigned int decDigit = (int)hexDigit - (int)'0' ;
108  if( decDigit > 9 )
109  decDigit = (int)hexDigit - (int)'a' + 10;
110  return decDigit;
111  }
118  static char dec2hexDigit( const unsigned int decDigit )
119  {
120  if( decDigit < 10 )
121  return (char)( decDigit + (int)'0');
122  else
123  return (char)( (decDigit-10)+(int)'a');
124  }
125 
126 };
127 
128 #endif
129 
130 
131 
static unsigned int hexDigit2dec(const char hexDigit)
Definition: d2hex.h:105
static char dec2hexDigit(const unsigned int decDigit)
Definition: d2hex.h:118
convert double numbers to hex strings and vice versa
Definition: d2hex.h:30
static string d2hex(const double d)
Definition: d2hex.h:69
static double hex2d(const string &hexer)
Definition: d2hex.h:43