它的功能执行什么样的操作? [英] What operation does the function perform?

查看:122
本文介绍了它的功能执行什么样的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int function(uint32_t *r, const uint32_t *a, const uint32_t *b, int n)
{
 int i;
 uint32_t ri, c=0;
 for (i = 0; i < n; i ++)
 {
   ri = a[i] + b[i] + c;
   c = ((ri < a[i]) || ((ri == a[i]) && c));
   r[i] = ri;
 }
   return ((int) c);
}

下面给出的C函数有四个参数:R,A和B都指向数组的指针
类型uint32_t的。整数n指定这些阵列(即所有三个数组的长度
含有相同数量的元素)。返回值的类型为int。能有人可以帮助我了解此函数执行的操作?

The C function given below has four arguments: r, a, and b are pointers to arrays of type uint32_t. The integer n specifies the length of these arrays (i.e. all three arrays contain the same number of elements). The return value is of type int. Can anyone could help me to understand the operation performed by this function?

推荐答案

据执行多precision除了用随身携带传播。在 A B 参数为指针,以多precision整数与 N 每个数字。在这种情况下,数字为32位。最不显著数字是最低数组索引。

It is performing multi-precision addition with carry propagation. The a and b arguments are pointers to multi-precision integers with n digits each. In this case, the digits are 32-bits. The least-significant digits are in the lowest array indices.

的输入,并将结果存入数组通过指向研究(也包含 N 32位数字)。它的工作原理是从 A A位b 通过进位添加一个数字ç,这是初始化为零。一个进行检测时得到的数字是输入数字小于1,或等于的数字之一时,进位为1的返回值是从整个操作的进位。

The inputs are added, and the result is placed into the array pointed to by r (also containing n 32-bit digits). It works by adding a digit from a to a digit from b with the carry-in c, which is initialized to zero. A carry out is detected when the resulting digit is less than one of the input digits, or is equal to one of the digits when the carry-in is 1. The return value is the carry-out from the whole operation.

想象一下,我们正在与基地10个数字增加。如果我们计算9 + 9 + 0模10,我们得到8.自8小于9,我们推断,一定有一个进位。如果我们计算9 + 9 + 1模10,我们得到9;我们推断进位,因为进位设置。如果我们计算9 + 0 + 0,我们得到9,但没有进位,因为进位为0。

Imagine we are adding with base-10 digits. If we compute 9+9+0 mod 10, we get 8. Since 8 is less than 9, we infer that there must have been a carry-out. If we compute 9+9+1 modulo 10, we get 9; we infer a carry-out because the carry-in was set. If we compute 9+0+0, we get 9, but there was no carry-out because carry-in was 0.

这篇关于它的功能执行什么样的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆