- switch (base)
- {
- case SC_HEX:
- for (counter = 0; counter < MAX_VALUE_SIZE; counter++)
- {
- if (val[counter] < SC_A)
- *(--pos) = val[counter] + '0';
- else
- *(--pos) = val[counter] + 'a' - 10;
+ /* special case */
+ if (bits == 0) {
+ bits = BIT_PATTERN_SIZE;
+#ifdef STRCALC_DEBUG_FULLPRINT
+ bits <<= 1;
+#endif
+ }
+ nibbles = bits >> 2;
+ switch (base) {
+
+ case SC_HEX:
+ digits = big_digits;
+ case SC_hex:
+ for (counter = 0; counter < nibbles; ++counter) {
+ *(--pos) = digits[_val(val[counter])];
+#ifdef STRCALC_DEBUG_GROUPPRINT
+ if ((counter+1)%8 == 0)
+ *(--pos) = ' ';
+#endif
+ }
+
+ /* last nibble must be masked */
+ if (bits & 3) {
+ x = and_table[_val(val[++counter])][bits & 3];
+ *(--pos) = digits[_val(x)];
+ }
+
+ /* now kill zeros */
+ for (; counter > 1; --counter, ++pos) {
+#ifdef STRCALC_DEBUG_GROUPPRINT
+ if (pos[0] == ' ') ++pos;
+#endif
+ if (pos[0] != '0')
+ break;
+ }
+ break;
+
+ case SC_BIN:
+ for (counter = 0; counter < nibbles; ++counter) {
+ pos -= 4;
+ p = binary_table[_val(val[counter])];
+ pos[0] = p[0];
+ pos[1] = p[1];
+ pos[2] = p[2];
+ pos[3] = p[3];
+ }
+
+ /* last nibble must be masked */
+ if (bits & 3) {
+ x = and_table[_val(val[++counter])][bits & 3];
+
+ pos -= 4;
+ p = binary_table[_val(x)];
+ pos[0] = p[0];
+ pos[1] = p[1];
+ pos[2] = p[2];
+ pos[3] = p[3];
+ }
+
+ /* now kill zeros */
+ for (counter <<= 2; counter > 1; --counter, ++pos)
+ if (pos[0] != '0')
+ break;
+ break;
+
+ case SC_DEC:
+ case SC_OCT:
+ memset(base_val, SC_0, CALC_BUFFER_SIZE);
+ base_val[0] = base == SC_DEC ? SC_A : SC_8;
+
+ p = val;
+ sign = 0;
+ if (base == SC_DEC) {
+ /* check for negative values */
+ if (_bit(val, bits - 1)) {
+ _negate(val, div2_res);
+ sign = 1;
+ p = div2_res;