Question: (C code) let say I have an unsinged int that holds 32 bits and I have three variable that each holds a decimal number. let's

(C code) let say I have an unsinged int that holds 32 bits and I have three variable that each holds a decimal number. let's say I have decimal number 40 200 and 15000. the second number in binary i changed into two complement. I want to pack them in 32 bits and I have tried doing a bitwise or of three of the numbers like this.

some function called pack(unsigned int* sun, int brightness, int elevation, int raduis)

unsigned int *result.

int brightness = 40; reserve first nine bits int elevation = 200;reserve the next 8 bits in 2s complement int radius = 15000; the last15 bits

what i tried:

unsigned int pack_32 = brightness << 25 | 9 >> ~(elevation) +1 << 19| raduis;

result = &pack_32;

I am worried that the two complement is going to clip or overwrite through the first 9 bits. I am trying to keep the first nine bits preserved.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!