source:
trunk/IPs/systemC/processor/Morpheo/Include/ToBase2.h
@
8
Last change on this file since 8 was 2, checked in by , 18 years ago | |
---|---|
File size: 452 bytes |
Rev | Line | |
---|---|---|
[2] | 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 | inline string toBase2 (uint32_t value, uint32_t size) | |
17 | { | |
18 | ostringstream res; | |
19 | uint32_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 | }; // end namespace morpheo | |
31 | ||
32 | #endif |
Note: See TracBrowser
for help on using the repository browser.