I’m trying to do some number conversions as below. Could someone please help me? I think I can do this a long way. I’d like to know if there is a simpler solution.

Let’s suppose there is a 32-bit hardware register called R.

R[31:15] = x

R[14:7] = y

R[6:0] = z

A user enters 3 decimal numbers: x, y, and z. The program then displays the resulting value of R[31:0] as a hex value. Since x is a 17-bit number, y an 8-bit, and z a 7-bit number, the range for each are different: x = {0, …, 131071}, y = {0, …, 255}, z = {0, …, 127}.

Example)

So, if I type in x = 255, y = 127, z = 63, it should display 0x007FBFBF (if I calculated this correctly).

I’d also like to be able to perform a reverse operation. The user enters a 32-bit hex value and the program slices it to 3 separate decimal numbers x, y, & z.

What’d be the easiest way to do this? I’m thinking of converting each decimal value to binary, concatenating them into one binary number, and then converting that into a hex value. Would this be the only way? Are there pre-built converts for decimal-to-binary, binary-to-hex, etc? I couldn’t locate it in JUCE doc.

Thanks for your help.