Bitstream Interpretation Library (BIL)  0.1
HexPrint.cpp
Go to the documentation of this file.
1 
6 #include <iomanip>
7 #include <sstream>
8 #include <util/HexPrint.hpp>
9 
10 using namespace bil;
11 
12 
13 void bil::printHex(std::ostream& os, boost::uint32_t word)
14 {
15  // print word in hexadecimal representation with fixed width of 8 digits and
16  // prefixed by 0x
17  os << std::hex << std::setfill('0') << "0x" << std::setw(8) << word;
18 }
19 
20 
21 void bil::printHex(std::ostream& os, const boost::uint32_t* words, size_t wordCount)
22 {
23  // print words in hexadecimal representation with fixed width of 8 digits
24  // and prefixed by 0x
25  os << std::hex << std::setfill('0');
26  for (size_t i = 0; i < wordCount; ++i)
27  {
28  os << "0x" << std::setw(8) << *words++;
29  if ((i+1) < wordCount) os << " ";
30  }
31 }
32 
33 
34 std::string bil::hexString(boost::uint32_t word)
35 {
36  // print word into a stringstream
37  std::stringstream ss;
38  printHex(ss, word);
39  // return stringstream content
40  return ss.str();
41 }
42 
43 
44 std::string bil::hexString(const boost::uint32_t* words, size_t wordCount)
45 {
46  // print words into a stringstream
47  std::stringstream ss;
48  printHex(ss, words, wordCount);
49  // return stringstream content
50  return ss.str();
51 }