math - How to apply modulo operation on a char array in C? -


edited:

i have big number c not have type natively. have use char array hold it. example, create 32-byte array. represents large number 2 ^ 256.

unsigned char num[32]; // size number question. 

i want apply modulo operation on it, example, want mod big number small divisor , integer type result.

int divisor = 1234; // note divisor smaller big number int result;  // here // produce result // result = number mod divisor 

i not want use other library. how can it?

to perform mod large number, use mod 1 unsigned char (@bathsheba) @ time.

% c's remainder operator. positive operands has same functionality mod.

unsigned mod_big(const unsigned char *num, size_t size, unsigned divisor) {   unsigned rem = 0;   // assume num[0] significant   while (size-- > 0) {     // use math done @ width wider `divisor`     rem = ((uchar_max + 1ull)*rem + *num) % divisor;     num++;   }   return rem; } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -