I'm trying to solve a question that says,
Initialize a new variable to the value 17512807u.
Assume we number the bits as usual from 0 as least significant (on the right) to 31 (most significant, on the left). Update bits 18 through 21 with the integer value 8 and bits 10 through 14 with value 17 (decimal). Print the resulting value as an eight digit hexadecimal number to show all of the digits.
I understand what I'm required to do, and my code is working fine, but I'm told that my answer is incorrect.
#include <stdio.h> int main(){ int value = 17512807u; int L = 21; // starting left position int R = 18; // starting right position int mask = (1 << (L - R + 1) - 1) << R; int newField = (8 << R) & mask; // integer value 8, shifting to right int newValue = value & (~mask); // remove range of bits value = newField | newValue; // update range of bits L = 14; R = 10; mask = (1 << (L - R + 1) - 1) << R; newField = (17 << R) & mask; newValue = value & (~mask); value = newField | newValue; printf("%08x\n", value); } Since I don't know the correct answer, and the only information I'm given is that my answer is wrong, I do not understand what I'm doing wrong.
inttype for17512807uvalue after being advised to useunsigned?