.Net(C#)常用转换byte转uint32、byte转float等

1、byte转String

Encoding.ASCII.GetString(byte\[\]);

2、base64string转byte

byte\[\]=Base64Decoder.Decoder.GetDecoded(string);

3、byte转UInt16

方法一

(UInt16)(bytes0 * 256 + bytes1)

方法二

(UInt16)((bytes0 << 8) | bytes1);

方法三

字节序要对应上,下位机一般高字节在前,C#这个函数是低字节在前

BitConverter.ToInt16(bytes);

4、byte转UInt32

(UInt32)((bytes0 << 24) | (bytes1 << 16) | (bytes2 << 8) | bytes3);

5、byte转Int32

(Int32)((bytes0 << 24) | (bytes1 << 16) | (bytes2 << 8) | bytes3);

6、byte转float

BitConverter.ToSingle(bytes, 0);

7、byte转char

BitConverter.ToSingle(bytes, 0);

相关推荐
大可不必了21 小时前
03 函数定义和调用
开发语言·python
I_belong_to_jesus21 小时前
C++关于分支预测的优化1
开发语言·c++·算法
承渊政道1 天前
【Python编程—从入门到实践】(记分与闯关:用Python+Pygame,打造越战越精彩的太空大战!)
开发语言·python·pycharm·游戏程序·pygame
爱学习的程序媛1 天前
Python常用框架梳理
开发语言·后端·python·ai·web·后端框架·python框架
eggwyw1 天前
Anaconda安装卸载的详细流程指南
开发语言·python
用户788477316341 天前
WinForms 迁移 WPF:Upgrade Assistant 覆盖 30%,剩下 70% 我手写了六周
c#
another heaven1 天前
【C/C++ Ranges 是零开销抽象吗?拆开管道、惰性求值和编译期膨胀】
c语言·开发语言·c++
SomeOtherTime1 天前
Rust 闭包语法和原理(AI回答)
开发语言·后端·rust
apcipot_rain1 天前
C++转Java日记(10)
java·开发语言
总要学点什么1 天前
第105篇:三维特效-流动图片墙体效果——让箭头沿墙长滚,它俩竟是同一份代码
开发语言·javascript·ecmascript·gis·webgl·材质·cesium