2字节十六进制浮点数 qt_Qt 中十六进制字节流转换为Base64编码
在Qt中,在網(wǎng)絡(luò)通信時(shí),有時(shí)需要將16進(jìn)制字節(jié)流轉(zhuǎn)換為Base64編碼傳輸,在Qt的QByteArray類中,提供了與Base64轉(zhuǎn)換的接口:
//16進(jìn)制字節(jié)流轉(zhuǎn)為Base64
QByteArray toBase64(Base64Options options) const;
QByteArray toBase64() const; // ### Qt6 merge with previous
//Base64轉(zhuǎn)為16進(jìn)制字節(jié)流
static QByteArray fromBase64(const QByteArray &base64, Base64Options options);
static QByteArray fromBase64(const QByteArray &base64); // ### Qt6 merge with previous
測(cè)試代碼如下:
#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數(shù)據(jù)轉(zhuǎn)換為base64編碼,轉(zhuǎn)換后賦值給base64Str
QString base64Str = data.toBase64();
//QByteArray::toHex(); //是將十六進(jìn)制數(shù)據(jù),按照其字面值轉(zhuǎn)換為字符串,比如: 0x12-->0x31 0x32,以字符串輸出時(shí)就是“12”
qDebug()<
QByteArray decBase64 = QByteArray::fromBase64(QString(base64Str).toLatin1());
qDebug()<
return a.exec();
}
執(zhí)行結(jié)果:
hexData: "0102030405060708090a" , base64: "AQIDBAUGBwgJCg=="
hexData: "0102030405060708090a"
總結(jié)
以上是生活随笔為你收集整理的2字节十六进制浮点数 qt_Qt 中十六进制字节流转换为Base64编码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: u盘装了pe读取不了怎么办 U盘装了PE
- 下一篇: pemicro识别不了驱动_usb驱动无