Rev 990 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 990 | Rev 997 | ||
|---|---|---|---|
| Line 94... | Line 94... | ||
| 94 | { |
94 | { |
| 95 | string hex; |
95 | string hex; |
| 96 | 96 | ||
| 97 | while (bin.size() > 0) |
97 | while (bin.size() > 0) |
| 98 | { |
98 | { |
| - | 99 | string part; |
|
| - | 100 | ||
| - | 101 | try |
|
| - | 102 | { |
|
| 99 |
|
103 | part = bin.substr(0, 4); |
| - | 104 | } |
|
| - | 105 | catch (std::out_of_range& e) |
|
| - | 106 | { |
|
| - | 107 | cout << "DEBUG: bin2hex exception: " << e.what() << "\n"; |
|
| - | 108 | cout << "DEBUG: A bin=" << bin << endl; |
|
| - | 109 | continue; |
|
| - | 110 | } |
|
| - | 111 | ||
| 100 | bin.erase(0, part.size()); |
112 | bin.erase(0, part.size()); |
| 101 | 113 | ||
| 102 | while (part.size() < 4) |
114 | while (part.size() < 4) |
| 103 | part = "0" + part; |
115 | part = "0" + part; |
| 104 | 116 | ||
| Line 138... | Line 150... | ||
| 138 | 150 | ||
| 139 | return hex; |
151 | return hex; |
| 140 | } |
152 | } |
| 141 | 153 | ||
| 142 | string float2bin(float num, int length) |
154 | string float2bin(float num, int length) |
| 143 | { |
155 | { |
| 144 | string bin; |
156 | string bin; |
| 145 | 157 | ||
| 146 | ///FIXME |
158 | ///FIXME |
| 147 | 159 | ||
| 148 | while (bin.size() < length) |
160 | while (bin.size() < length) |
| 149 | bin = "0" + bin; |
161 | bin = "0" + bin; |
| 150 | 162 | ||
| 151 | return bin; |
163 | return bin; |
| 152 | } |
164 | } |
| 153 | 165 | ||
| 154 | string hex2bin(string hex) |
166 | string hex2bin(string hex) |
| 155 | { |
167 | { |
| 156 | hex = strtolower(hex); |
168 | hex = strtolower(hex); |
| 157 | 169 | ||
| 158 | string bin; |
170 | string bin; |
| 159 | 171 | ||
| 160 | for (int n = 0; n < hex.length(); n++) |
172 | for (int n = 0; n < hex.length(); n++) |
| 161 | { |
173 | { |
| 162 | switch (hex[n]) |
174 | switch (hex[n]) |
| 163 | { |
175 | { |
| 164 | case '0': bin += "0000"; break; |
176 | case '0': bin += "0000"; break; |
| Line 184... | Line 196... | ||
| 184 | } |
196 | } |
| 185 | 197 | ||
| 186 | string uint2bin(unsigned int num, int length) |
198 | string uint2bin(unsigned int num, int length) |
| 187 | { |
199 | { |
| 188 | string bin; |
200 | string bin; |
| 189 | 201 | ||
| 190 | while (num) |
202 | while (num) |
| 191 | { |
203 | { |
| 192 | bin = char((num&1)+'0') + bin; |
204 | bin = char((num&1)+'0') + bin; |
| 193 | num >>= 1; |
205 | num >>= 1; |
| 194 | } |
206 | } |
| Line 210... | Line 222... | ||
| 210 | string::size_type startPos = 0; |
222 | string::size_type startPos = 0; |
| 211 | string::size_type endPos = 0; |
223 | string::size_type endPos = 0; |
| 212 | 224 | ||
| 213 | while ((endPos = str.find(delimiter, startPos)) != string::npos) |
225 | while ((endPos = str.find(delimiter, startPos)) != string::npos) |
| 214 | { |
226 | { |
| - | 227 | try |
|
| - | 228 | { |
|
| 215 | parts.push_back(str.substr(startPos, endPos-startPos)); |
229 | parts.push_back(str.substr(startPos, endPos-startPos)); |
| - | 230 | } |
|
| - | 231 | catch (std::out_of_range& e) |
|
| - | 232 | { |
|
| - | 233 | cout << "DEBUG: explode exception: " << e.what() << "\n"; |
|
| - | 234 | cout << "DEBUG: A str=" << str << " :: startPos=" << startPos << " :: endPos=" << endPos << endl; |
|
| - | 235 | continue; |
|
| - | 236 | } |
|
| - | 237 | ||
| 216 | startPos = endPos+delimiter.length(); |
238 | startPos = endPos+delimiter.length(); |
| 217 | } |
239 | } |
| 218 | 240 | ||
| 219 | if (startPos < str.length()) |
241 | if (startPos < str.length()) |
| 220 | { |
242 | { |
| - | 243 | try |
|
| - | 244 | { |
|
| 221 | parts.push_back(str.substr(startPos, str.length()-startPos)); |
245 | parts.push_back(str.substr(startPos, str.length()-startPos)); |
| - | 246 | } |
|
| - | 247 | catch (std::out_of_range& e) |
|
| - | 248 | { |
|
| - | 249 | cout << "DEBUG: explode exception: " << e.what() << "\n"; |
|
| - | 250 | cout << "DEBUG: B str=" << str << " :: startPos=" << startPos << " :: endPos=" << endPos << endl; |
|
| - | 251 | } |
|
| 222 | } |
252 | } |
| 223 | 253 | ||
| 224 | return parts; |
254 | return parts; |
| 225 | } |
255 | } |
| 226 | 256 | ||