Last change
on this file since 104 was
103,
checked in by moulu, 16 years ago
|
1) write queue vhdl
2) bug fix : in generic queue
|
-
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 103 2009-01-16 16:55:32Z moulu $ |
---|
| 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); |
---|
[103] | 19 | |
---|
| 20 | for (uint32_t i=0; i<size; ++i) |
---|
[2] | 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.