Answer to Question #244971 in C for harry

Question #244971

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.


1
Expert's answer
2021-09-30T14:23:25-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS