Changeset 52 for sources/src/bit2string.cc
- Timestamp:
- Jan 22, 2013, 4:23:22 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/src/bit2string.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : bit2string.cc |6 | |7 | Author : Kingbo Paul-Jerome |8 | Buchmann Richard |9 | |10 | Date : 09_07_2004 |11 | |12 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : bit2string.cc | 6 | | 7 | Author : Kingbo Paul-Jerome | 8 | Buchmann Richard | 9 | | 10 | Date : 09_07_2004 | 11 | | 12 \------------------------------------------------------------*/ 13 13 14 14 /* … … 37 37 #include "bit2string.h" 38 38 #include "sc_unit.h" 39 39 40 #include <cstdarg> 40 41 #include <cstdio> 41 42 #include <cstdlib> 42 43 #include <iostream> 44 43 45 #ifdef HAVE_CONFIG_H 44 46 #include "config.h" 45 47 #endif 46 48 47 49 using namespace std; 48 50 49 51 namespace sc_core { 50 52 51 static 52 void bit2string_64 (char *buf, tab_t *val,int size) 53 { 54 typedef sc_dt::s_uint_type<64>::uint_type data_type; 55 data_type tmp=*((data_type*)val); 56 //cout << "tmp = " << tmp << "\n"; 57 buf[size]='\0'; 58 for (int i=size-1; i>=0;--i) 59 { 60 buf[i]=(tmp&1)?'1':'0'; 61 tmp>>=1; 62 } 63 #if 0 64 cout << buf << "\n"; 65 #endif 53 static void bit2string_64(char * buf, tab_t * val, int size) { 54 typedef sc_dt::s_uint_type<64>::uint_type data_type; 55 data_type tmp = *((data_type *) val); 56 buf[size] = '\0'; 57 for (int i = size - 1; i >= 0; --i) { 58 buf[i] = (tmp & 1) ? '1' : '0'; 59 tmp >>= 1; 60 } 66 61 } 67 62 68 static 69 void bit2string_32 (char *buf, tab_t *val,int size) 70 { 71 typedef sc_dt::s_uint_type<32>::uint_type data_type; 72 data_type tmp=*((data_type*)val); 73 //cout << "tmp = " << tmp << "\n"; 74 buf[size]='\0'; 75 for (int i=size-1; i>=0;--i) 76 { 77 buf[i]=(tmp&1)?'1':'0'; 78 tmp>>=1; 79 } 80 #if 0 81 cout << buf << "\n"; 82 #endif 63 static void bit2string_32(char * buf, tab_t * val, int size) { 64 typedef sc_dt::s_uint_type<32>::uint_type data_type; 65 data_type tmp = *((data_type *) val); 66 buf[size] = '\0'; 67 for (int i = size - 1; i >= 0; --i) { 68 buf[i] = (tmp & 1) ? '1' : '0'; 69 tmp >>= 1; 70 } 83 71 } 84 72 85 void bit2string(char *buf, tab_t *val,int bit_number) 86 { 87 if (bit_number > 32) 88 { 89 bit2string_64 (buf, (tab_t*)val, bit_number); 90 return; 91 } else if (bit_number > 16) 92 { 93 bit2string_32 (buf, (tab_t*)val, bit_number); 94 return; 95 } 96 tab_t tmp=*((tab_t*)val); 97 //cout << "tmp = " << tmp << "\n"; 98 buf[bit_number]='\0'; 99 for (int i=bit_number-1; i>=0;--i) 100 { 101 buf[i]=(tmp&1)?'1':'0'; 102 tmp>>=1; 103 } 104 73 void bit2string(char * buf, tab_t * val, int bit_number) { 74 if (bit_number > 32) { 75 bit2string_64(buf, (tab_t *) val, bit_number); 76 return; 77 } 78 else if (bit_number > 16) { 79 bit2string_32(buf, (tab_t *) val, bit_number); 80 return; 81 } 82 tab_t tmp = *((tab_t *) val); 83 buf[bit_number] = '\0'; 84 for (int i = bit_number - 1; i >= 0; --i) { 85 buf[i] = (tmp & 1) ? '1' : '0'; 86 tmp >>= 1; 87 } 88 105 89 } 106 90 107 char * strip (char * buf)108 { 109 int cpt=0; 110 while ( (buf[cpt] == '0') && (buf[cpt+1] != '\0') ) //tant que bit == 0 111 cpt++; 112 return (buf+cpt);91 char * strip(char * buf) { 92 int cpt = 0; 93 while ((buf[cpt] == '0') && (buf[cpt + 1] != '\0')) {// tant que bit == 0 94 cpt++; 95 } 96 return (buf + cpt); 113 97 } 114 98 115 99 } // end of sc_core namespace 116 100 101 102 /* 103 # Local Variables: 104 # tab-width: 4; 105 # c-basic-offset: 4; 106 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 107 # indent-tabs-mode: nil; 108 # End: 109 # 110 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 111 */ 112
Note: See TracChangeset
for help on using the changeset viewer.