I'm really sorry for the wording of the question, it's a bit confusing.
So lets say I have a buffer:
char buffer[4] = {0, 0, 2, 0};
if we convert it all to binary, we get one 32 bit unsigned int:
00000000 00000000 00000010 00000000
The value of it is 512.
So my question is, how do I get to the answer of 512 using c++? Preferably with some library function.
Thanks for any answer, and I'm very sorry if this has been asked before, I couldn't find it.
You can perform some bitwise operations:
unsigned int converter(const char buffer[4]) {
return (buffer[0] << 24) |
(buffer[1] << 16) |
(buffer[2] << 8) |
(buffer[3]);
}
Example Here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With