如何在CAPL中将字节数组转换为字符串?

安东尼·何塞

我有一个字节数组,我需要在一行中打印元素。

我尝试使用 ' snprintf()' 但它不会将字节数组作为其输入参数。

我尝试将字节数组复制到整数数组中,然后使用snprintf(), 但不是打印 HEX 值,而是打印相应的 ASCII 值。

奥利维尔

你可以试试这个代码:

variables
{ 
  int ar[100];
}

on diagResponse TCCM.*
{
  char tmp[8];    // Temporary buffer containing single HEX value
  char out[301];  // Bigger output string and "local" to function
  // Better to place them there (i and response) if they are not global
  int i;
  byte response[100];
  
  out[0] = 0;     // Clear output string
  
  s1 = DiagGetPrimitiveData(this, response, elcount(response));

  for (i = 0; i < s1; i++)
  { 
    ar[i] = response[i];
    snprintf(tmp, elcount(tmp), "%.2X ", response[i]);  // byte to HEX convert
    strncat(out, tmp, elcount(out));  // Concatenate HEX value to output string
  }

  write("HEX Response : %s", out);
}

奥利维尔

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Go中将字节数组转换为字符串数组?

如何在Java中将字节数组转换为十六进制字符串?

如何在Java中将字符串转换为bcd格式的字节数组?

如何在PowerShell中将哈希字符串转换为字节数组?

如何在C#中将字节数组的子范围转换为字符串

如何在php中将字符串转换为ascii字节数组

如何在JNI中将Java字节数组的内容转换为C字符串?

如何在Crystal中将十六进制字符串转换为字节数组?

在python中将字节数组的字符串转换为字节数组

如何在Python中将具有非ASCII字节的字节数组转换为字符串?

如何在Go中将字符串转换为使用给定字符集编译的字节数组?

如何在Java中将具有空终止符的字节数组转换为字符串?

如何在android中将输入流转换为字节数组到字符串

如何在Swift中将UInt8字节数组转换为字符串

如何在ctypes中将无符号字节数组转换为base64字符串

如何在Swift中将十六进制字符串转换为UInt8字节数组?

如何在Java中从字节数组转换为字符串以删除填充字符?

从字符串数组转换为字节数组

将表示为字符串的字节数组转换为字节数组

将字节数组转换为字符串

在 C# 中将十六进制字符串转换为字节数组

在GJS中将字符串转换为UTF-16字节数组

在Go中将字符串转换为固定大小的字节数组

在javascript中将字节数组转换为字符串

在Python中将ASCII代码列表转换为字符串(字节数组)

在Android中将字节数组转换为Base64字符串

在Kotlin中将字节数组转换为字符串

在PHP中将字节数组转换为字符串

如何在Android中将字节数组转换为不包含0x00字符的字符串