]> git.donarmstrong.com Git - biopieces.git/blob - code_c/Maasha/src/lib/common.c
41dc8c255bc9c789578e295c11982735d041629c
[biopieces.git] / code_c / Maasha / src / lib / common.c
1 /* Martin Asser Hansen (mail@maasha.dk) Copyright (C) 2008 - All right reserved */
2
3 #include "common.h"
4 #include "list.h"
5 #include "mem.h"
6
7
8 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MISC <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
9
10
11 char *bits2string( uint bin )
12 {
13     /* Martin A. Hansen, June 2008 */
14     
15     /* Return a binary number as a string of 1's and 0's. */
16
17     int   i;
18     uint  j;
19     char *string;
20     
21     string = mem_get( ( sizeof( uint ) * 8 ) + 1 );
22
23     j = 1;
24                                                                                                                                 
25     for ( i = 0; i < sizeof( uint ) * 8; i++ )                                                                          
26     {                                                                                                                           
27                                                                                                                                 
28         if ( ( bin & j ) != 0 ) {                                                                                               
29             string[ 31 - i ] = '1';                                                                                             
30         } else {                                                                                                                
31             string[ 31 - i ] = '0';                                                                                             
32         }                                                                                                                       
33                                                                                                                                 
34         j <<= 1;                                                                                                                
35     }                                                                                                                           
36                                                                                                                                 
37     string[ i ] = '\0';                                                                                                         
38                                                                                                                                 
39     return string;                                                                                                              
40 }
41
42
43 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/