Changeset 10425 for trunk/FACT++/src/Converter.cc
- Timestamp:
- 04/20/11 15:24:14 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Converter.cc
r10387 r10425 211 211 T Converter::Get(std::stringstream &line) const 212 212 { 213 char c; 214 line >> c; 215 216 if (c=='0') 217 { 218 if (line.peek()==-1) 219 return 0; 220 221 if (line.peek()=='x') 222 line >> hex; 223 else 224 line >> oct; 225 226 line.unget(); 227 } 228 229 line.unget(); 230 213 231 T val; 214 232 line >> val; … … 331 349 return stream.str(); 332 350 } 333 334 // --------------------------------------------------------------------------335 //336 //! Converts from a binary block into a hex representation.337 //!338 //! @param dat339 //! Pointer to the data block340 //!341 //! @param size342 //! Size of the data block343 //!344 //! @param chunk345 //! Size of the size of hex chunks seperted by a ':' in bytes346 //!347 //! @returns348 //! The string349 //!350 string Converter::GetHex(const void *dat, size_t size, size_t chunk)351 {352 const unsigned char *ptr = reinterpret_cast<const unsigned char *>(dat);353 354 ostringstream text;355 356 text << hex;357 358 for (size_t i=0; i<size; i++)359 {360 text << setw(2) << setfill('0') << (unsigned int)ptr[i];361 if ((i%chunk)==chunk-1)362 text << ":";363 }364 365 return text.str();366 }367 368 351 369 352 // --------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.