simple bitwise question

How can I create a unit32 value, from a list<uint8> ??? ...if its not a few lines of code..please point me in the right direction(other than the bitwise tutorials..)

Thanks.
http://www.cplusplus.com/reference/stl/list/

Mind you, a uint8 is most likely an unsigned char, 8 bits opposed to 32.
Last edited on
then what?...
list<uint8> foolist = getFooList();

int fooListInt = ???


???= what do i put here to convert that foolist to an integer that i can convert back to list<uint8> in the right order.
i mean list<uint8> to a uint32
It depends on how uint8 in the list form uint32. If for example the first element of the list corresponds to the highest byte of the uint32 then you can use std::accumulate. For example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <iterator>

int main()
{
	typedef unsigned char uint8;
	typedef unsigned int uint32;
	std::list<uint8> l = { 1, 2, 3, 4 };


	uint32 value = std::accumulate( l.begin(), std::next( l.begin(), 4 ), 0,
		                            []( uint32 s, uint8 x )
		                                {
								return ( ( s << 8 ) + x );
		                                } );

	std::cout << "value = " << std::hex << value << std::endl;  
}
Last edited on
thanks. I will study this to figure out 'exactly' what was done to get to the unit32..and this accumulate lib.
Topic archived. No new replies allowed.