Last change
on this file since 60 was
43,
checked in by rosiere, 17 years ago
|
Modif mineur : ajout d'info de débug
Release non stable
|
File size:
1.1 KB
|
Line | |
---|
1 | #ifndef morpheo_ToBase2 |
---|
2 | #define morpheo_ToBase2 |
---|
3 | |
---|
4 | /* |
---|
5 | * $Id$ |
---|
6 | * |
---|
7 | * [ Description ] |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | #include <sstream> |
---|
12 | using namespace std; |
---|
13 | |
---|
14 | namespace morpheo { |
---|
15 | |
---|
16 | template<typename T> inline std::string toBase2 (const T& value, const uint32_t & size) |
---|
17 | { |
---|
18 | ostringstream res; |
---|
19 | T mask = 1<<(size-1); |
---|
20 | |
---|
21 | while (mask != 0) |
---|
22 | { |
---|
23 | res << ((value&mask)?'1':'0'); |
---|
24 | mask >>= 1; |
---|
25 | } |
---|
26 | |
---|
27 | return res.str(); |
---|
28 | } |
---|
29 | |
---|
30 | inline std::string toBase2 (const bool & value) |
---|
31 | { |
---|
32 | return toBase2<bool > (value, 1); |
---|
33 | } |
---|
34 | |
---|
35 | inline std::string toBase2 (const uint8_t & value, const uint32_t & size) |
---|
36 | { |
---|
37 | return toBase2<uint8_t> (value, size); |
---|
38 | } |
---|
39 | |
---|
40 | inline std::string toBase2 (const uint16_t& value, const uint32_t & size) |
---|
41 | { |
---|
42 | return toBase2<uint16_t> (value, size); |
---|
43 | } |
---|
44 | |
---|
45 | inline std::string toBase2 (const uint32_t& value, const uint32_t & size) |
---|
46 | { |
---|
47 | return toBase2<uint32_t> (value, size); |
---|
48 | } |
---|
49 | |
---|
50 | inline std::string toBase2 (const uint64_t& value, const uint32_t & size) |
---|
51 | { |
---|
52 | return toBase2<uint64_t> (value, size); |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | }; // end namespace morpheo |
---|
57 | |
---|
58 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.