- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我需要帮助来获得仅针对字母数字字符(不包括特殊字符)的 ascii 到十六进制数据输出。
Input String is: 86741-30011
Expected result is: 38363734313330303131
Actual Result is: 3836373431
输出在非字母数字字符后中断。它只包含输出字符串,直到非字母数字字符。
代码:
int main(void){
char word[12] = { '8', '6','7','4','1','-','3','0','0','1','1'};
char outword[20];
int i, len;
len = strlen(word);
printf("Input string: %s\n", word);
//printf("Total length: %d\n", len);
if(word[len-1]=='\n') word[--len] = '\0';
for(i = 0; i<len; i++) {
if (isalnum(word[i]) == 0) {
printf("%c is not an alphanumeric character.\n", word[i]);
} else {
sprintf(outword+i*2 , "%02X", word[i]);
}
}
printf("Hex output:%s\n", outword); return 0;
}
任何人都可以帮助我获得预期的输出吗?
提前致谢。
最佳答案
使用不同的变量进行循环旋转并将数据添加到数组中。
#include <stdio.h>
int main(void){
char word[12] = { '8', '6','7','4','1','-','3','0','0','1','1'};
char outword[20];
int i, j, len;
len = strlen(word);
printf("Input string: %s\n", word);
//printf("Total length: %d\n", len);
if(word[len-1]=='\n') word[--len] = '\0';
for(i = 0,j=0; i<len; i++) {
if (isalnum(word[i]) == 0) {
printf("%c is not an alphanumeric character.\n", word[i]);
} else {
sprintf(outword+j*2 , "%02X", word[i]);
j=j+1;
}
}
printf("Hex output:%s\n", outword); return 0;
}
此代码将为您提供预期结果 38363734313330303131。
关于c - 在 C 中将 ASCII 转换为 HEX 时跳过特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50715481/
你好,我是 SMARTRF-05EB - 评估板的新手,我已经在 Linux 虚拟机中安装了 SDCC 和 Contiki-2.6。我能够构建此目录 contiki-2.6/contiki/examp
下面的简单代码会产生奇怪的输出: #include #include #include "/tmp/sha.h" #define DIGEST 64 //taken from coreutils
我不知道为什么 Hex 函数返回一个像 '0x41' 而不是 0x41 的字符串 我需要将 ASCII 值转换为十六进制。但我想要 0x INT 格式,而不是 '0x' 字符串。 ascii = 36
所以我试图从十六进制文件中读取,修改十六进制值,将新的十六进制值写入新文件。然后打开新文件,再次修改十六进制并重写到第三个文件。我正在对十六进制值进行非常简单的加密。 我用来阅读的函数是休闲的: ve
是否有一种惯用的方式将 Clojure 中的字符串编码和解码为十六进制?来自 Python 的示例: 'Clojure'.encode('hex') # ⇒ '436c6f6a757265' '436
下面的函数可以完美地将字符串转换为十六进制: function String2Hex(const Buffer: AnsiString): string; begin SetLength(Resu
我要做的是将 double 字符串转换为十六进制字符串,然后再转换回 double 。 以下代码将 double 字符串转换为十六进制字符串。 char * double2HexString(doub
我正在尝试将整数转换为十六进制。我找到了解决此问题的答案,例如 this ,尽管它们对我不起作用。我的意思是: 如果我拿这个: buf = "" buf += "\xda\xc7\xd9\x74\x
许多在线示例将哈希显示为十六进制表示,它们通常是自定义实现。改用 Apache Commons Base64 编码有什么问题或安全性降低吗?在阅读有关编码的内容时,通常是在如何将二进制表示为 XML
我需要存储这种类型的值 0xff0000或 0x00ff08 (十六进制颜色表示)在solidity智能合约中,并且能够在合约内将其转换为具有相同文本字符的字符串"ff0000" .我打算在 RSK
如果我有两种颜色: #ffcc00 和#334455 我如何获得这两种颜色之间的所有#hex 颜色,并逐渐排序? 最佳答案 你可以试试这个工具: http://www.colorhexa.com/ff
我的命令输出类似于 0x53 0x48 0x41 0x53 0x48 0x49。现在我需要将其存储在十六进制值中,然后将其转换为 ASCII 作为 SHASHI。 我试过的- 我尝试将十六进制值存储为
我正在使用计算 16 位 CRC 校验和的函数。 该函数生成一个包含校验和的 LONG(以 10 为基数的数字格式)。当然,这可以以十六进制等效形式打印到控制台,如下所示: printf("Check
我有一些以 INTEGER 形式提供给我的数字数据。我将它与其他数据一起插入到 SQLite 中,但当我将其写出时 INTEGER 数字需要为 8 位 Hex 数字,前导零。 例如 输入 400 80
在尝试附加数据对象转换为十六进制值后,我有如下代码,但它给了我以下错误: Unexpectedly found nil while unwrapping an Optional value let n
我有三个程序。程序A的代码如下: #include "stdafx.h" #include #include #include using namespace std; int _tmain(
我得到了这段代码,它从十六进制转换为 base64,反之亦然。我从另一个 SO 问题中得到了 to_base64,然后我通过一些猜测和反复试验编写了 to_hex。 class String de
我有一些关于控制建筑物访问的磁卡的信息,并且需要对软件在卡上存储数据的方式进行逆向工程,以制作具有更多功能的东西。 (我们已经和原来的程序员失去了联系。) 我不知道如何编写订单;我不是磁卡专家。 我知
我想在我拥有的 HEX 文件中找到模式并按出现次数对它们进行排序。 我不是在寻找某种特定的模式,只是为了对那里发生的事件进行一些统计并对其进行排序。 DB0DDAEEDAF7DAF5DB1FDB1DD
我在出示卡片时从 RFID 阅读器接收字节,但我无法弄清楚如何从这些字节中获取卡 ID。 例如,我有一张卡片,上面印有这些数字: 0007625328 116,23152 .我希望这是那张卡的 ID,
我是一名优秀的程序员,十分优秀!