base_converter.h
Go to the documentation of this file.
1 #ifndef cetlib_base_converter_h
2 #define cetlib_base_converter_h
3 
4 // ==================================================================
5 //
6 // base_converter : Arbitary precision base conversion
7 //
8 // ==================================================================
9 
10 #include <string>
11 
12 namespace cet {
13  class base_converter;
14 }
15 
16 // ==================================================================
17 
19 public:
20  std::string const& get_source_base_set() const;
21  std::string const& get_target_base_set() const;
22  unsigned int get_source_base() const;
23  unsigned int get_target_base() const;
24 
25  base_converter(std::string const& sourceBaseSet,
26  std::string const& targetBaseSet);
27 
29  static std::string bin_to_dec(std::string value);
30  static std::string dec_to_hex(std::string value);
31  static std::string hex_to_dec(std::string value);
32 
33  std::string convert(std::string value) const;
34 
35 private:
36  static unsigned int divide(std::string const& baseDigits,
37  std::string& x,
38  unsigned int y);
39 
40  static unsigned int base2dec(std::string const& baseDigits,
41  std::string const& value);
42 
43  static std::string dec2base(std::string const& baseDigits,
44  unsigned int value);
45 
46 private:
47  static constexpr char const*
49  {
50  return "01";
51  }
52  static constexpr char const*
54  {
55  return "0123456789";
56  }
57  static constexpr char const*
59  {
60  return "0123456789ABCDEF";
61  }
62 
65 };
66 
67 inline std::string const&
69 {
70  return source_base_set_;
71 }
72 
73 inline std::string const&
75 {
76  return target_base_set_;
77 }
78 
79 inline unsigned int
81 {
82  return (unsigned int)source_base_set_.length();
83 }
84 
85 inline unsigned int
87 {
88  return (unsigned int)target_base_set_.length();
89 }
90 
91 #endif /* cetlib_base_converter_h */
92 
93 // Local Variables:
94 // mode: c++
95 // End:
static constexpr char const * binary_set()
std::string string
Definition: nybbler.cc:12
static unsigned int base2dec(std::string const &baseDigits, std::string const &value)
static std::string dec_to_hex(std::string value)
base_converter(std::string const &sourceBaseSet, std::string const &targetBaseSet)
std::string convert(std::string value) const
static constexpr char const * decimal_set()
static std::string dec2base(std::string const &baseDigits, unsigned int value)
unsigned int get_source_base() const
std::string const & get_source_base_set() const
static unsigned int divide(std::string const &baseDigits, std::string &x, unsigned int y)
static std::string dec_to_bin(std::string value)
std::string const & get_target_base_set() const
static constexpr char const * hex_set()
std::string source_base_set_
static std::string hex_to_dec(std::string value)
unsigned int get_target_base() const
std::string target_base_set_
list x
Definition: train.py:276
static std::string bin_to_dec(std::string value)