ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Represent/Hexadecimal.cpp
Revision: 371
Committed: 2004-12-21T23:19:54-08:00 (20 years, 6 months ago) by douglas
File size: 1037 byte(s)
Log Message:
Sleepy.

File Contents

# User Rev Content
1 douglas 371 // Represent
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include "Hexadecimal.hpp"
8    
9     Hexadecimal::Hexadecimal(const ext::String& string, bool signed_) : Binary(string.GetSize() / 2, 0)
10     {
11     if (string.IsEmpty())
12     {
13     bytes.InsertLast(0);
14    
15     return;
16     }
17    
18     size_t index(string.GetSize() % 2), offset(index);
19    
20     _rmforeach (ext::Vector<byte_t>, byte, bytes) _rfor (byte_t, half, 0, 2)
21     {
22     /* byte_t hex(string[index++]);
23    
24     if (hex >= '0' && hex <= '9') hex -= '0'; else*/
25     }
26    
27     if (offset != 0)
28     {
29     bytes.InsertLast(0);
30    
31     //
32    
33     index = 0;
34    
35     //
36     }
37     }
38    
39     Hexadecimal::operator ext::String() const
40     {
41     ext::String string;
42    
43     _rforeach (ext::Vector<byte_t>, byte, bytes) _rfor (byte_t, half, 0, 2)
44     {
45     byte_t hex(0xF & *byte >> half * 4);
46    
47     switch (hex)
48     {
49     case 0xA:
50     hex = 'A';
51    
52     break;
53     case 0xB:
54     hex = 'B';
55    
56     break;
57     case 0xC:
58     hex = 'C';
59    
60     break;
61     case 0xD:
62     hex = 'D';
63    
64     break;
65     case 0xE:
66     hex = 'E';
67    
68     break;
69     case 0xF:
70     hex = 'F';
71    
72     break;
73     default:
74     hex += '0';
75     }
76    
77     string.InsertLast(hex);
78     }
79    
80     return string;
81     }

Properties

Name Value
svn:eol-style native
svn:keywords Id