Short answer, yes.
I'm not going to worry about how you wrote your binary numbers. I will enter them in hex and let you look for binary representations by this related SO question: Can I use a binary literal in C or C++?
#include "stdafx.h" // you are using devstudio
#include <Windows.h> // you are using windows types
#include <iostream> // I print out the result
#include <bitset> // I use bitset to print the binary string
int main()
{
UINT8 var1 = 0x01; //0000 0001
UINT8 var2 = 0x03; //0000 0011
UINT8 var3 = 0x07; //0000 0111
UINT8 var4 = 0x0F; //0000 1111
UINT32 bigvar = (var1 << 24) + (var2 << 16) + (var3 << 8) + var4;
std::cout << std::bitset<32>(bigvar) << std::endl;
}
Your math is correct and safe. The bytes are independently declared, so you don't have to worry about byte order. The types are all unsigned, so no UB issues with the sign bit. The shifts all fit in the correct bit count, so no overflow. I generated:
00000001000000110000011100001111
Alternatively, you could have read in a 32 bit integer as 4 bytes, and reconstructed the 32 bit number, but that would not be portable, because sometimes the numbers are stored in reverse order. For example, in TIFF, you read in a header value which tells you whether you would put var1 first and count up, or var4 first and count down. Byte order is something you have to watch out for in almost all practical applications of combining a bunch of bytes into a larger integer type. Look up big-endian and little-endian for more info.