【问题标题】:Convert an array to an unsigned integer将数组转换为无符号整数
【发布时间】:2013-09-06 07:06:03
【问题描述】:

您好,我有一个二维的array[8][8],元素填充有10。所以我的问题是:如何将一整行转换为 8 位长的无符号整数?

我正在用 C 编写代码。

【问题讨论】:

  • 你试过了吗?显示您的代码..

标签: c arrays int unsigned


【解决方案1】:

像这样:

int array[8][8]; /* this is what you have */

unsigned row0 = 0;
int i;
for( i = 0; i < 8; i++ ) row0 |= (unsigned)array[0][i] << i;

/* row0 now contains the converted number */

这假设您的数据首先是最低有效位。

【讨论】:

  • OP 希望整数为 1 字节长。 unsigned 通常有四个字节长。
  • 是的,没关系,我只是想要转换的一般概念。我实际上使用的是 unsigned long long
猜你喜欢
  • 2012-05-10
  • 2012-01-09
  • 1970-01-01
  • 1970-01-01
  • 2017-07-21
  • 1970-01-01
  • 1970-01-01
  • 2012-03-03
相关资源
最近更新 更多