How Does the GET_UINT32 Macro Convert Input into Hexadecimal Format?

Click For Summary
The GET_UINT32 macro converts a sequence of bytes from an input array into a 32-bit unsigned integer by shifting and combining the bytes. It takes four consecutive bytes starting from a specified index, shifts them to their respective positions, and performs a bitwise OR to create the final value. An example shows that inputting the byte sequence corresponding to 3435973836 (0xcccccccc) results in the hexadecimal output 0x4E6F7726, which equals 1315927840. The discussion highlights confusion around how the macro processes the input and the significance of the bit shifts. Understanding this macro is essential for those studying cryptography and data manipulation in programming.
cutesteph
Messages
62
Reaction score
0

Homework Statement


this is in my function
GET_UINT32( X, input, 0 );

this is a macro
#define GET_UINT32(n,b,i) \
{ \
(n) = ( (uint32) (b)[(i) ] << 24 ) \
| ( (uint32) (b)[(i) + 1] << 16 ) \
| ( (uint32) (b)[(i) + 2] << 8 ) \
| ( (uint32) (b)[(i) + 3] ); \
}

3435973836=0xcccccccc
when inputted into the macro, it out puts
0x4E6F7726 =1315927840.Oxcc, Oxcc, Oxcc, Oxcc, Oxcc, Oxcc, Oxcc, Oxcc
into
0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74

The Attempt at a Solution


I am not sure how to begin. I am taking a cryptography class [/B]for fun as a statistics major. I tried understanding it but it just confused me. I want to see how (uint32) (b)[(i) + 1] << 16 ) changes the input
 
Last edited:
Physics news on Phys.org
cutesteph said:

Homework Statement


this is in my function
GET_UINT32( X, input, 0 );

this is a macro
#define GET_UINT32(n,b,i) \
{ \
(n) = ( (uint32) (b)[(i) ] << 24 ) \
| ( (uint32) (b)[(i) + 1] << 16 ) \
| ( (uint32) (b)[(i) + 2] << 8 ) \
| ( (uint32) (b)[(i) + 3] ); \
}

3435973836=0xcccccccc
when inputted into the macro, it out puts
0x4E6F7726 =1315927840.Oxcc, Oxcc, Oxcc, Oxcc, Oxcc, Oxcc, Oxcc, Oxcc
into
0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74

The Attempt at a Solution


I am not sure how to begin. I am taking a cryptography class [/B]for fun as a statistics major. I tried understanding it but it just confused me. I want to see how (uint32) (b)[(i) + 1] << 16 ) changes the input
Please show us all of your code.
 
and use the code tags when you do it.
 

Similar threads

  • · Replies 22 ·
Replies
22
Views
5K
Replies
9
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K