How to convert an unsigned 24-bit int to a signed int and character up to 32 bits?

I am trying to encode an ARM architecture branch instruction into a printout (converting a 32-bit number to an assembly). For branch instructions. I need to increase the signed_immed_24 value to 32 bits and shift it to the left to get the value for the assembly code.

Currently an unsigned integer. I was wondering if anyone has any helpful tips for converting it to a signed integer, converting 9991764 to -6785452. And then logically moving to the left to give the final answer -27141808

32-bit data is contained in a specific data structure.

/* Branch Instruction format data set */ typedef struct { uint32_t in; int cnd; char *cndbits; char *cndname; int IOO; char *IOObits; char *IOOname; int L; char *Lbits; char *Lname; int im; char *imbits; char *imname; } arm_b; 

Where im is the integer value to be converted.

This is a function that (at work) prints assembly code.

 /* prints the assembly language of the branch instruction */ void print_b_ass(arm_b *b_instr) { printf("\t B 0x3e61d950 <PC + -27141808 (-6785452 << 2)>\n\n"); } 
+4
source share
1 answer

If I understand what you are asking for:

 int a = 9991764; a <<= 8; a /= 64; // a = -27141808 

(I changed this to a break from the right shift, because according to the standard, the standard says that the shift can be logical and not arithmetic. I believe that the difference will ultimately be a uniform shift)

Also assumes a 32-bit int.

+1
source

All Articles