Write a C programm to Store a 256-bit unsigned integer number on a 32 byte character array. Add two such 256-bit numbers and print the result.
#include <stdio.h>
#include <inttypes.h>
int main() {
uint32_t a[8]; // 8 * 32 = 256
uint32_t b[8]; // 8 * 32 = 256
uint32_t c[8];
uint32_t max = (1 << 31);
uint32_t bit = 0;
// adding
for (size_t i = 7; i >= 0; i++) {
if (max - a[i] > b[i]) bit = 0;
else bit = 1;
c[i] = b[i] + a[i] + bit;
}
for (size_t i = 0; i < 8; i++) {
printf("%" PRId32, c[i]);
}
return 0;
}
Comments
Leave a comment