有谁知道我如何制作一个将十六进制值分配给4x4数组中的整行的C程序?每行将有一个值。(0x00、0xff,0x55和0xff)然后它需要对所有我可以做的元素求和。
#include "msp430g2553.h"
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
//--------------------------------------------------------------------------
//char type is one byte; int type is two bytes; volatile to prevent optimization
//------------------------------------------------------------------------------
volatile unsigned int i=0, j=0, sum=0; // sum is the sum of the indices
int Zeroes = 0x00, Ones = 0xff, Odds = 0x55, Evens = 0xaa;
unsigned char ArrayFill [4][4];
//------------------------------------------------------------------------------
// Initialize ArrayFill to 0xff
//------------------------------------------------------------------------------
{
for (i=0; i<=3; i++)
for (j=0; j<=3; j++)
ArrayFill[i][j] = 0xff;
}
//------------------------------------------------------------------------------
// Fill ArrayFill with the indices values and calculate the sum of the indices
//------------------------------------------------------------------------------
{
for (i=0; i<=3; i++)
{
for (j=0; j<=3; j++)
{
ArrayFill[i][j] = ????????;
sum=??????;
}
}
}
sum = sum;
最佳答案
我建议您初始化unsigned char
数据类型中的十六进制值。
例如:
unsigned char hex[4][4];
for(i=0;i<4;i++){
for(j=0;j<4;j++){
scan("%s",hex[i][j]);
}
}