2字节十六进制浮点数 qt_Qt 中十六进制字节流转换为Base64编码
在Qt中,在網絡通信時,有時需要將16進制字節流轉換為Base64編碼傳輸,在Qt的QByteArray類中,提供了與Base64轉換的接口:
//16進制字節流轉為Base64
QByteArray toBase64(Base64Options options) const;
QByteArray toBase64() const; // ### Qt6 merge with previous
//Base64轉為16進制字節流
static QByteArray fromBase64(const QByteArray &base64, Base64Options options);
static QByteArray fromBase64(const QByteArray &base64); // ### Qt6 merge with previous
測試代碼如下:
#include
#include
#include
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
char hexData[10]={0x1, 0x2, 0x3,0x4, 0x5,0x6,0x7,0x8,0x9,0xa};
QByteArray data = QByteArray(hexData, 10);
//hex數據轉換為base64編碼,轉換后賦值給base64Str
QString base64Str = data.toBase64();
//QByteArray::toHex(); //是將十六進制數據,按照其字面值轉換為字符串,比如: 0x12-->0x31 0x32,以字符串輸出時就是“12”
qDebug()<
QByteArray decBase64 = QByteArray::fromBase64(QString(base64Str).toLatin1());
qDebug()<
return a.exec();
}
執行結果:
hexData: "0102030405060708090a" , base64: "AQIDBAUGBwgJCg=="
hexData: "0102030405060708090a"
總結
以上是生活随笔為你收集整理的2字节十六进制浮点数 qt_Qt 中十六进制字节流转换为Base64编码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: u盘装了pe读取不了怎么办 U盘装了PE
- 下一篇: pemicro识别不了驱动_usb驱动无