Changeset 373 for trunk/lib


Ignore:
Timestamp:
Jun 19, 2007, 11:53:16 PM (16 years ago)
Author:
Peter Johansson
Message:

adding function transforming decimal int to hexadecimal refs #200

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/utility.cc

    r313 r373  
    7979
    8080
     81  std::string hex(int x, u_int width)
     82  {
     83    std::stringstream ss;
     84    ss << std::hex << x;
     85    if (!width)
     86      return ss.str();
     87    if (ss.str().size()<width)
     88      return std::string(width-ss.str().size(), '0') + ss.str();
     89    return ss.str().substr(0, width);
     90  }
     91
     92
    8193  std::string htrim(std::string str)
    8294  {
  • trunk/lib/utility.h

    r371 r373  
    6363  ///
    6464  std::string getenv(const std::string& var);
     65
     66  ///
     67  /// If @a width is set, size is forced to length @a width. This
     68  /// implies, e.g., that hex(15,2) and hex(17,1) return "0F" and "1",
     69  /// respectively.
     70  ///
     71  /// @return x in hexadecimal base
     72  ///
     73  std::string hex(int x, u_int width=0);
    6574
    6675  ///
Note: See TracChangeset for help on using the changeset viewer.