Last change
on this file since 98 was
88,
checked in by rosiere, 16 years ago
|
Almost complete design
with Test and test platform
|
-
Property svn:keywords set to
Id
|
File size:
1.1 KB
|
Rev | Line | |
---|
[88] | 1 | #ifndef Morpheo_ToBase2_h |
---|
| 2 | #define Morpheo_ToBase2_h |
---|
[2] | 3 | |
---|
| 4 | /* |
---|
| 5 | * $Id: ToBase2.h 88 2008-12-10 18:31:39Z rosiere $ |
---|
| 6 | * |
---|
| 7 | * [ Description ] |
---|
| 8 | * |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | #include <sstream> |
---|
| 12 | |
---|
| 13 | namespace morpheo { |
---|
| 14 | |
---|
[41] | 15 | template<typename T> inline std::string toBase2 (const T& value, const uint32_t & size) |
---|
[2] | 16 | { |
---|
[75] | 17 | std::ostringstream res; |
---|
[41] | 18 | T mask = 1<<(size-1); |
---|
| 19 | |
---|
[2] | 20 | while (mask != 0) |
---|
| 21 | { |
---|
| 22 | res << ((value&mask)?'1':'0'); |
---|
| 23 | mask >>= 1; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | return res.str(); |
---|
| 27 | } |
---|
[41] | 28 | |
---|
| 29 | inline std::string toBase2 (const bool & value) |
---|
| 30 | { |
---|
| 31 | return toBase2<bool > (value, 1); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | inline std::string toBase2 (const uint8_t & value, const uint32_t & size) |
---|
| 35 | { |
---|
| 36 | return toBase2<uint8_t> (value, size); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | inline std::string toBase2 (const uint16_t& value, const uint32_t & size) |
---|
| 40 | { |
---|
| 41 | return toBase2<uint16_t> (value, size); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | inline std::string toBase2 (const uint32_t& value, const uint32_t & size) |
---|
| 45 | { |
---|
| 46 | return toBase2<uint32_t> (value, size); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | inline std::string toBase2 (const uint64_t& value, const uint32_t & size) |
---|
| 50 | { |
---|
| 51 | return toBase2<uint64_t> (value, size); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
[2] | 55 | }; // end namespace morpheo |
---|
| 56 | |
---|
| 57 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.