gpt4 book ai didi

c# - 如何将单个字节转换为字符串

转载 作者:太空狗 更新时间:2023-10-29 18:05:54 25 4
gpt4 key购买 nike

我在 Visual Studio 2010 中使用 C#。

我想将一个字节(8 位整数)转换为一个字符长的字符串。我需要这样做,因为我想通过串行方式将字节值发送到 Arduino。

比如说,假设

byte myByte = 49;

49 是字符“1”的 ASCII 码。我想将 myByte 转换为 myString,这样如果我这样做了

serialport1.Write(myString);

它的功能与

相同
serialport1.Write("1");

谁能帮帮我?

最佳答案

System.Text.Encoding.ASCII.GetString(new[]{myByte})

关于c# - 如何将单个字节转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22135275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com