Tag: hex

如何正确地将TAG值转换为正确的格式以便validationHMAC?

我正在进行HMAC生成和validation以检查数据完整性。 我可以正确生成MAC值但是当通过套接字将其发送到另一个程序进行validation时,我遇到格式不匹配。 我感谢您的支持。 谢谢。 unsigned char* MAC(unsigned char* key,unsigned char* message) { unsigned char* result; unsigned int result_len = 32; int i; result = (unsigned char*) malloc(sizeof(char) * result_len); result = HMAC(EVP_sha256 (), key , strlen (key), message , strlen(message) , NULL, NULL); return result; } int verifyMAC(unsigned char* key,unsigned char* message, unsigned char* receivedTag) […]

将Char *缓冲区转换为hex,以便在c 中打印

嗨我试图将char缓冲区中的值打印为hex值为(“0X%x”), char buffer[1024] printf(“recived (0x%x) from the client\n”,buffer); 但编译代码时有警告: server.c:105:5: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘char *’ [-Wformat] 那怎么解决这个问题????

如何将hex数字打印到文件?

我试图将0000到fffe的每个hex值存储到一个文件中。 我如何使用fwrite或fprintf将这些值放入文件中? 目前,我有一个while循环,使用printf打印所有数字(这是控制台屏幕),但我需要在文件中。

使用C中的fscanf读取一系列HEX值(每次2个)

所以我有一个文本文件,假设名为text.txt。 其格式为: 4C 4D 4E 4F (即字符串“LMNO”的hex值)。 我已正确打开文本文件等。我应该如何使用fscanf读取四个字节的序列(即一次1个字节),将每个字节存储在一个变量中(具有适当的数据类型)。 我的最终目标是了解如何在字符数组中存储char test[4]; 字母LMNO (即test [0] =’L’,test [1] =’M’,…)

签名hex字符串到long int函数

我需要一个函数将32位或24位带符号(二进制补码)hex字符串转换为long int。 需要在32位和64位机器上工作(无论长度大小如何),无论机器是否是双补机,都需要工作。 解: long int hex2li (char hexStr[], int signedHex) { int bits = strlen (hexStr) * 4; char *pEnd; long long int result = strtoll (hexStr, &pEnd, 16); if (pEnd[0] == ‘\0’) { if (signedHex) { if (result >= (1LL << (bits – 1))) result -= (1LL << bits); } return (long int) […]

C编程中的Hex文件读取?

我有一个问题: 我正在编写的ac程序,其function与hex编辑器非常相似。 我想接收一个文件并查看其hex值。 例如,假设我的文本文件“helloworld.txt”只有“Hello World!”字样。 在其中,我想指定程序获取该文件,读取其hex值(同样该文件是一个简单的.txt文件,而不是二进制文件)并将其存储在一个数组中供以后使用。 这是我到目前为止: #include #include int main() { char ch, file_name[25]; FILE *fp; printf(“Enter the name of file you wish to see\n”); gets(file_name); fp = fopen(file_name,”rb”); // read binary mode if( fp == NULL ) //error checking { perror(“Error while opening the file.\n”); exit(EXIT_FAILURE); } printf(“The contents of %s file are […]

hex查找和替换

如何在二进制文件中更改二进制文件hex字符? #include #include #include #define BUFFER_SIZE 4096 int main(void) { uint8_t *buffer; // Explicit 8 bit unsigned, but should equal “unsigned char” FILE *file; char filename[512] = “test.bin”; // We could also have used buffer[BUFFER_SIZE], but this shows memory alloc if (NULL == (buffer = malloc(BUFFER_SIZE))) { fprintf(stderr, “out of memory\n”); return -1; } // […]

在串行通信中获取错误数据

我正在制作一个简单的C程序,以便从串行设备串行获取数据。 数据采用hex格式。 在编写代码之前,我在cutecom中检查了它,我收到了25 54 00 1e ,这是正确和准确的值。 但是当我编写代码然后我收到这个错误数据的BFE50A14 。 我不知道我在哪里弄错了,请帮忙。 谢谢。! 码: #include #include #include #include #include #include #include #include #define portname “/dev/ttyUSB0” int set_interface_attribs (int fd, int speed, int parity) { struct termios tty; memset (&tty, 0, sizeof tty); if (tcgetattr (fd, &tty) != 0) { // error_message (“error %d from tcgetattr”, errno); printf(“error […]

将MFRC522 UIDhex字节转换为可打印的十进制

我在我的Arduino UNO上使用MFRC522库来阅读Mifare RFID标签信息。 // Print HEX UID Serial.print(“Card UID:”); for (byte i = 0; i < mfrc522.uid.size; i++) { Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); Serial.print(mfrc522.uid.uidByte[i], HEX); } Serial.println(); 我有一个包含HEX UID的字节数组(4): 54 C7 FD 5A 但我没能将它转换为十进制: HEX(5AFDC754) => DEC(1526581076) 我试图将字节数组转换为char反向,但编译器没有让我打印Dec。 char str[8]; int k = 0; for (int i = 3; i […]

C中的char * string到hex arrary

我有char * para.mac ,字符串c8934641d0b7存储在其中。 我想将它转换为hex数组int m[6] ,make m[0]=0xc8; m[1]=0x93; … m[5]=0xb7; 我试着这样做: int i; int m[6]; sscanf(para.mac, “%x%x%x%x%x%x”, &m[0], &m[1], &m[2], &m[3], &m[4], &m[5]); for(i=0;i<6;i++) printf("%i \r\n",m[i]); 但它似乎不起作用。 而且我不知道为什么结果对我显示如下: 1178718391 0 0 134448233 8 134272063 我认为应该是 200(0xc8) 147(0x93) 70(0x46) 65(0x41) 208(0xd0) 183(0xb7) 所以有什么问题?