KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
Hexa_t.cpp
1#include "Hexa_t.h"
2#include "Riostream.h"
3#include "TMath.h"
4#include "TString.h"
5#include "Binary_t.h"
6
8TString Hexa_t::fPrefix = "0x"; //default prefix for hexadecimal numbers
9
10
13
15{
16 //Create hexa number
17 fVal = 0;
18}
19
20
21
24
26{
27 //Create hexa number corresponding to decimal value "val"
28 fVal = val;
29}
30
31
32
35
37{
38 //Create hexa number from string containing hexa value
39 Set(val);
40}
41
42
43
46
47void Hexa_t::Set(const Long64_t val)
48{
49 //Set number corresponding to decimal value "val"
50 fVal = val;
51}
52
53
54
57
59{
60 //Get decimal value of number
61 return fVal;
62}
63
64
65
70
71void Hexa_t::Set(const Char_t* val)
72{
73 //Set value from string containing hexa number
74 //Can be written in lower or upper case.
75 //Acceptable formats are "a0D4", "0xff21" and "$f5"
76
77 TString tmp(val);
78 tmp.ToUpper();
79 if (tmp.BeginsWith("0X"))
80 tmp.Remove(0, 2);
81 if (tmp.BeginsWith("$"))
82 tmp.Remove(0, 1);
83 UInt_t xval;
84 sscanf(tmp.Data(), "%X", &xval);
85 Set((Long64_t) xval);
86}
87
88
89
96
98{
99 //Return pointer to string containing hexadecimal representation of number
100 //This string should be copied immediately before further use.
101 //The prefix used to represent hexadecimal numbers is "0x" by default.
102 //This can be changed using SetPrefix.
103
104 //use Form's circular Char_t buffer to return pointer
105 return (Form("%s%llx", fPrefix.Data(), (ULong64_t)Value()));
106}
107
108
109
112
114{
115 //Assign a decimal value to the Hexa number
116 Set(val);
117 return (*this);
118}
119
120
121
124
126{
127 //Assign a Hexa value (as a string) to the Hexa number
128 Set(val);
129 return (*this);
130}
131
132
133// Hexa_t& Hexa_t::operator=(const Binary_t& val)
134// {
135// //Assign a binary value to the Hexa number
136// Set(val.Value());
137// return (*this);
138// }
139
140
143
145{
146 //Assign a hexadecimal value to the Hexa number
147 Set(val.Value());
148 return (*this);
149}
150
151
152//
153
156
158{
159 //Addition of two Hexa numbers
160 return Hexa_t(b1.Value() + fVal);
161}
162
163
164// Hexa_t Hexa_t::operator+(const Binary_t& b1)
165// {
166// //Addition of two Hexa numbers
167// return Hexa_t(b1.Value() + fVal);
168// }
169
170
173
175{
176 //Addition of two Hexa numbers
177 return Hexa_t(l1 + fVal);
178}
179
180
181
184
186{
187 //Addition of two Hexa numbers
188 return Hexa_t(c1) + (*this);
189}
190
191
192//--------------------------------------------------bitwise OR operators
193
194// Hexa_t operator|(const Hexa_t& b1, const Hexa_t& b2)
195// {
196// //bitwise OR of two Hexa numbers
197// Hexa_t tmp(b1.Value() | b2.Value());
198// return tmp;
199// }
200//
201// Hexa_t operator|(const Hexa_t& b1, const Long64_t l2)
202// {
203// //bitwise OR of two Hexa numbers
204// Hexa_t tmp(b1.Value() | l2);
205// return tmp;
206// }
207//
208// Hexa_t operator|(const Long64_t l1, const Hexa_t& b2)
209// {
210// //bitwise OR of two Hexa numbers
211// Hexa_t tmp(l1 | b2.Value());
212// return tmp;
213// }
214//
215// Hexa_t operator|(const Hexa_t& b1, const Char_t* c2)
216// {
217// //bitwise OR of two Hexa numbers
218// Hexa_t b2(c2);
219// Hexa_t tmp(b1.Value() | b2.Value());
220// return tmp;
221// }
222//
223// Hexa_t operator|(const Char_t* c1, const Hexa_t& b2)
224// {
225// //bitwise OR of two Hexa numbers
226// Hexa_t b1(c1);
227// Hexa_t tmp(b1.Value() | b2.Value());
228// return tmp;
229// }
230//
231// //--------------------------------------------------bitwise AND operators
232//
233// Hexa_t operator&(const Hexa_t& b1, const Hexa_t& b2)
234// {
235// //bitwise AND of two Hexa numbers
236// Hexa_t tmp(b1.Value() & b2.Value());
237// return tmp;
238// }
239//
240// Hexa_t operator&(const Hexa_t& b1, const Long64_t l2)
241// {
242// //bitwise AND of two Hexa numbers
243// Hexa_t tmp(b1.Value() & l2);
244// return tmp;
245// }
246//
247// Hexa_t operator&(const Long64_t l1, const Hexa_t& b2)
248// {
249// //bitwise AND of two Hexa numbers
250// Hexa_t tmp(l1 & b2.Value());
251// return tmp;
252// }
253//
254// Hexa_t operator&(const Hexa_t& b1, const Char_t* c2)
255// {
256// //bitwise AND of two Hexa numbers
257// Hexa_t b2(c2);
258// Hexa_t tmp(b1.Value() & b2.Value());
259// return tmp;
260// }
261//
262// Hexa_t operator&(const Char_t* c1, const Hexa_t& b2)
263// {
264// //bitwise AND of two Hexa numbers
265// Hexa_t b1(c1);
266// Hexa_t tmp(b1.Value() & b2.Value());
267// return tmp;
268// }
269
270
275
277{
278 //Set bit 'nbit' to 1
279 //The least significant bit is numbered 0.
280 //If "val" is given, bit 'nbit' is set to the same value as the equivalent bit in 'val'
281
282 if (val + 1) { //default value of val=-1, so any value >= 0 will make this true
283 if (TESTBIT(val, nbit))
284 SetBit(nbit);
285 else
286 ResetBit(nbit);
287 }
288 else
289 SETBIT(fVal, nbit);
290}
291
292
293
297
299{
300 //Set bit 'nbit' to 0
301 //The least significant bit is numbered 0.
302
303 CLRBIT(fVal, nbit);
304}
305
306
307
311
313{
314 //Returns kTRUE if bit is equal to '1'
315 //The least significant bit is numbered 0.
316
317 return TESTBIT(fVal, nbit);
318}
319
320
321// Binary_t Hexa_t::Binary() const
322// {
323// //Return binary equivalent of number
324// return Binary_t(Value());
325// }
326
327// void Hexa_t::TestBinary()
328// {
329// //Test binary template clas
330// Binary16_t a(3), b("1101"), c(a);
331// a.Print(); b.Print(); c.Print();
332// cout << "//--------------------------------------------//" << endl;
333// Binary16_t d=16, e="11001", f=a;
334// d.Print(); e.Print(); f.Print();
335// cout << "//--------------------------------------------//" << endl;
336// a.Set("111111"); b.Set(53);
337// a.Print(); b.Print();
338// cout << "//--------------------------------------------//" << endl;
339// c=a;
340// b="101010";
341// a=16;
342// a.Print(); b.Print(); c.Print();
343// cout << "//--------------------------------------------//" << endl;
344// a.WriteSubvalue(42, 7, 6);
345// a.Print();
346// cout << (int)c.Subvalue(3,4) <<endl;
347// cout << "//--------------------------------------------//" << endl;
348//
349// }
350
unsigned int UInt_t
bool Bool_t
unsigned char UChar_t
char Char_t
#define SETBIT(n, i)
#define TESTBIT(n, i)
#define CLRBIT(n, i)
char * Form(const char *fmt,...)
Hexadecimal numbers.
Definition Hexa_t.h:15
Long64_t fVal
Definition Hexa_t.h:17
Hexa_t operator+(const Hexa_t &b1)
Addition of two Hexa numbers.
Definition Hexa_t.cpp:157
const Char_t * String(UChar_t nbits=0) const
Definition Hexa_t.cpp:97
void Set(const Long64_t)
Set number corresponding to decimal value "val".
Definition Hexa_t.cpp:47
Hexa_t & operator=(const Long64_t)
Assign a decimal value to the Hexa number.
Definition Hexa_t.cpp:113
Hexa_t()
Create hexa number.
Definition Hexa_t.cpp:14
Bool_t TestBit(UChar_t)
Definition Hexa_t.cpp:312
Long64_t Value() const
Get decimal value of number.
Definition Hexa_t.cpp:58
void ResetBit(UChar_t)
Definition Hexa_t.cpp:298
void SetBit(UChar_t, Long64_t=-1)
Definition Hexa_t.cpp:276
static TString fPrefix
the prefix used to represent hexadecimal numbers as strings
Definition Hexa_t.h:18
const char * Data() const
void ToUpper()
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Remove(EStripType s, char c)
long long Long64_t
unsigned long long ULong64_t
return c1
ClassImp(TPyArg)