* @version $Id$
*/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
-#ifdef HAVE_STRING_H
-# include <string.h> /* memset/memcmp */
-#endif
+#include <stdlib.h>
+#include <string.h> /* memset/memcmp */
#include <assert.h> /* assertions */
#include <stdio.h> /* output for error messages */
#include <limits.h> /* definition of LONG_MIN, used in sc_get_val_from_long */
goto end;
case -1: /* dividend < divisor */
- memcpy(rem, rDividend, calc_buffer_size);
+ memcpy(rem, dividend, calc_buffer_size);
goto end;
default: /* unluckily division is necessary :( */
carry_flag = 1;
/* shift digits to the right with offset, carry and all */
- counter = 0;
- if ((bitsize >> 2) > shift_nib) {
- buffer[counter] = shrs_table[_val(val1[shift_nib])][shift_mod][0];
- counter = 1;
- }
- for (; counter < bitsize/4 - shift_nib; counter++) {
+ buffer[0] = shrs_table[_val(val1[shift_nib])][shift_mod][0];
+ for (counter = 1; counter < ((bitsize + 3) >> 2) - shift_nib; counter++) {
shrs = shrs_table[_val(val1[counter + shift_nib])][shift_mod];
- buffer[counter] = shrs[0];
- buffer[counter-1] = or_table[_val(buffer[counter-1])][_val(shrs[1])];
+ buffer[counter] = shrs[0];
+ buffer[counter - 1] = or_table[_val(buffer[counter-1])][_val(shrs[1])];
}
/* the last digit is special in regard of signed/unsigned shift */
case 'c':
case 'b':
case 'a':
- if (base[0] > SC_9 || base[1] > SC_0) { /* (base > 10) */
+ if (base[0] > SC_A || base[1] > SC_0) { /* (base > 10) */
val[0] = _digit((*str)-'a'+10);
}
else
case 'C':
case 'B':
case 'A':
- if (base[0] > SC_9 || base[1] > SC_0) { /* (base > 10) */
+ if (base[0] > SC_A || base[1] > SC_0) { /* (base > 10) */
val[0] = _digit((*str)-'A'+10);
}
else
case '9':
case '8':
- if (base[0] > SC_7 || base[1] > SC_0) { /* (base > 8) */
+ if (base[0] > SC_8 || base[1] > SC_0) { /* (base > 8) */
val[0] = _digit((*str)-'0');
}
else
return -1;
}
+int sc_get_bit_at(const void *value, unsigned pos) {
+ const char *val = value;
+ unsigned nibble = pos >> 2;
+
+ if (and_table[(int) val[nibble]][(int) shift_table[pos & 3]] != SC_0)
+ return 1;
+ return 0;
+}
+
+void sc_set_bit_at(void *value, unsigned pos)
+{
+ char *val = value;
+ unsigned nibble = pos >> 2;
+
+ val[nibble] = or_table[(int)val[nibble]][(int)shift_table[pos & 3]];
+}
+
int sc_is_zero(const void *value) {
const char* val = (const char *)value;
int counter;
/* last nibble must be masked */
if (bits & 3) {
- mask = zex_digit[bits & 3];
+ mask = zex_digit[(bits & 3) - 1];
x = and_table[_val(val[counter++])][mask];
*(--pos) = digits[_val(x)];
}
/* last nibble must be masked */
if (bits & 3) {
- mask = zex_digit[bits & 3];
+ mask = zex_digit[(bits & 3) - 1];
x = and_table[_val(val[counter++])][mask];
pos -= 4;
/* last nibble must be masked */
if (bits & 3) {
- mask = zex_digit[bits & 3];
+ mask = zex_digit[(bits & 3) - 1];
div1_res[counter] = and_table[_val(p[counter])][mask];
++counter;
}