@@ -33,14 +33,36 @@ void printData(asciiParams params){
3333 procCol = currCol ;
3434 }
3535
36- snprintf (tmp , sizeof (tmp ), "%03o " , params .content [s ]);
37- if (params .onlyOct || params ._onlyAll ) strcat (lines [currRow ],tmp );
36+ if (params .onlyOct || params ._onlyAll ){
37+ snprintf (tmp , sizeof (tmp ), "%03o " , params .content [s ]);
38+ strcat (lines [currRow ],tmp );
39+ }
40+
41+ if (params .onlyDec || params ._onlyAll ){
42+ snprintf (tmp , sizeof (tmp ), "%3d " , params .content [s ]);
43+ strcat (lines [currRow ],tmp );
44+ }
3845
39- snprintf (tmp , sizeof (tmp ), "%3d " , params .content [s ]);
40- if (params .onlyDec || params ._onlyAll ) strcat (lines [currRow ],tmp );
46+ if (params .onlyHex || params ._onlyAll ){
47+ snprintf (tmp , sizeof (tmp ), " %2X " , params .content [s ]);
48+ strcat (lines [currRow ],tmp );
49+ }
4150
42- snprintf (tmp , sizeof (tmp ), " %2X " , params .content [s ]);
43- if (params .onlyHex || params ._onlyAll ) strcat (lines [currRow ],tmp );
51+ if (params .onlyBin /*|| params._onlyAll*/ ){
52+ uint8_t index = 0 ; uint8_t content = params .content [s ];
53+ uint8_t binStr [9 ] = "00000000\0" ;
54+
55+ for (uint8_t i = 128 ; i > 0 && content != 0 ; i = (i /2 )){
56+ if (content >= i ){
57+ binStr [index ] = '1' ;
58+ content -= i ;
59+ }
60+ index ++ ;
61+ }
62+
63+ snprintf (tmp , sizeof (tmp ), "%s " , binStr );
64+ strcat (lines [currRow ],tmp );
65+ }
4466
4567 if (isPrintable (params .content [s ])){
4668 snprintf (tmp , sizeof (tmp ),YEL "%c " RESET , params .content [s ]);
@@ -64,12 +86,13 @@ void printData(asciiParams params){
6486 s ++ ;
6587 }
6688
67- uint16_t colLineLength = (params .onlyOct || params ._onlyAll ?5 :0 ) + (params .onlyDec || params ._onlyAll ?5 :0 ) + (params .onlyHex || params ._onlyAll ?5 :0 ) + (params .onlyChar || params ._onlyAll ?5 :0 );
89+ uint16_t colLineLength = (params .onlyOct || params ._onlyAll ?5 :0 ) + (params .onlyDec || params ._onlyAll ?5 :0 ) + (params .onlyHex || params ._onlyAll ?5 :0 ) + (params .onlyBin /*|| params._onlyAll*/ ? 10 : 0 ) + ( params . onlyChar || params ._onlyAll ?5 :0 );
6890
6991 for (uint8_t i = 0 ; i < col ; i ++ ){
7092 if (params .onlyOct || params ._onlyAll ) printf ("Oct " );
7193 if (params .onlyDec || params ._onlyAll ) printf ("Dec " );
7294 if (params .onlyHex || params ._onlyAll ) printf ("Hex " );
95+ if (params .onlyBin /*|| params._onlyAll*/ ) printf ("Binary " );
7396 if (params .onlyChar || params ._onlyAll ) printf (YEL "Chr" RESET );
7497
7598 if (col != i + 1 ){
@@ -85,8 +108,8 @@ void printData(asciiParams params){
85108 uint8_t * hyphens = (uint8_t * )calloc ( (size_t )maxLength [i ],sizeof (uint8_t ));
86109 memset (hyphens , (uint8_t )45 , sizeof (uint8_t ) * (size_t )maxLength [i ]);
87110
88- uint8_t * fHyphens = (uint8_t * )calloc ( params ._onlyAll ?19 : (params .onlyDec ?5 :0 ) + (params .onlyOct ?5 :0 ) + (params .onlyHex ?5 :0 ) + (params .onlyChar ?4 :0 ),sizeof (uint8_t ));
89- memset (fHyphens , (uint8_t )45 , sizeof (uint8_t ) * (params ._onlyAll ?19 : (params .onlyDec ?5 :0 ) + (params .onlyOct ?5 :0 ) + (params .onlyHex ?5 :0 ) + (params .onlyChar ?4 :0 )));
111+ uint8_t * fHyphens = (uint8_t * )calloc ( params ._onlyAll ?( params . onlyBin ? 19 + 10 : 19 ): (params .onlyDec ?5 :0 ) + (params .onlyOct ?5 :0 ) + (params .onlyHex ?5 : 0 ) + ( params . onlyBin ? 10 :0 ) + (params .onlyChar ?4 :0 ),sizeof (uint8_t ));
112+ memset (fHyphens , (uint8_t )45 , sizeof (uint8_t ) * (params ._onlyAll ?( params . onlyBin ? 19 + 10 : 19 ): (params .onlyDec ?5 :0 ) + (params .onlyOct ?5 :0 ) + (params .onlyHex ?5 : 0 ) + ( params . onlyBin ? 10 :0 ) + (params .onlyChar ?4 :0 )));
90113
91114 printf ("%s%s" ,fHyphens ,hyphens );
92115 if (col - 1 != i ) printf ("+--" );
@@ -101,8 +124,8 @@ void printData(asciiParams params){
101124 uint8_t * hyphens = (uint8_t * )calloc ( (size_t )maxLength [i ],sizeof (uint8_t ));
102125 memset (hyphens , (uint8_t )45 , sizeof (uint8_t ) * (size_t )maxLength [i ]);
103126
104- uint8_t * fHyphens = (uint8_t * )calloc ( params ._onlyAll ?19 : (params .onlyDec ?5 :0 ) + (params .onlyOct ?5 :0 ) + (params .onlyHex ?5 :0 ) + (params .onlyChar ?4 :0 ),sizeof (uint8_t ));
105- memset (fHyphens , (uint8_t )45 , sizeof (uint8_t ) * (params ._onlyAll ?19 : (params .onlyDec ?5 :0 ) + (params .onlyOct ?5 :0 ) + (params .onlyHex ?5 :0 ) + (params .onlyChar ?4 :0 )));
127+ uint8_t * fHyphens = (uint8_t * )calloc ( params ._onlyAll ?( params . onlyBin ? 19 + 10 : 19 ): (params .onlyDec ?5 :0 ) + (params .onlyOct ?5 :0 ) + (params .onlyHex ?5 : 0 ) + ( params . onlyBin ? 10 :0 ) + (params .onlyChar ?4 :0 ),sizeof (uint8_t ));
128+ memset (fHyphens , (uint8_t )45 , sizeof (uint8_t ) * (params ._onlyAll ?( params . onlyBin ? 19 + 10 : 19 ): (params .onlyDec ?5 :0 ) + (params .onlyOct ?5 :0 ) + (params .onlyHex ?5 : 0 ) + ( params . onlyBin ? 10 :0 ) + (params .onlyChar ?4 :0 )));
106129
107130 printf ("%s%s" ,fHyphens ,hyphens );
108131 if (col - 1 != i ) printf ("+--" );
0 commit comments