转换向量子集<uint8_t>到 int [英] convert subset of vector<uint8_t> to int

查看:26
本文介绍了转换向量子集<uint8_t>到 int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何将十六进制值向量转换为十进制长整数.

I am having trouble figuring out how to convert an vector of hex values to a decimal long int.

    vector<uint8_t>v;

    v.push_back(0x02);
    v.push_back(0x08);
    v.push_back(0x00);
    v.push_back(0x04);
    v.push_back(0x60);
    v.push_back(0x50);
    v.push_back(0x58);
    v.push_back(0x4E);
    v.push_back(0x01);
    v.push_back(0x80);

//How would I achieve this:
    long time =  0x00046050584E0180; //1,231,798,102,000,000

如何将向量 v 的元素 2-9 转换为长整数,如上面表示的具有长时间".

How would I get elements 2-9 for the vector v into an long int like represented above with the long 'time'.

谢谢!

推荐答案

这里的基本原则是:

int x = 0; 
for(uint8_t i : v)
{
   x <<= 8; 
   x |= i;
}

这篇关于转换向量子集&lt;uint8_t&gt;到 int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆