If you ever had to work with controllers or microprocessors, you’ve probably come across the need to convert 2 cells of 16 bits numbers into a single 32bit integers. On some controllers, the registers are assigned in 16-bit cells, and if you want to store anything larger than 65,535 you’ll need to convert it.

In this quick tip you can see a C# function for doing exactly that:

Even though this code is given in C#, it is relevant for other languages as well. The idea is to shift the most significant bits left, and then performing a bitwise OR on the least significant bits.

I’ll add other functions like that in the future.

Leave a comment