将1Byte数据转换为4Byte时会发生什么

tbo*_*bol 2 c c++ casting

我正在尝试根据C/C++中的RFC1321实现MD5算法,并且在类型转换方面存在一些问题.

typedef unsigned int uint4;  // 32 Bit (4 Byte)
typedef unsigned char uint1; //  8 Bit (1 Byte)

// pseudocode
uint1 byte = {1,0,0,1,1,1,1,0}; // 0b10011110
uint4 t_uint4 = (uint4)byte;

uint4 = { ??? }

// maybe like this??
uint4 = { {1,0,0,1,1,1,1,0},{???},{???},{???} }
uint4 = { {???},{???},{???},{1,0,0,1,1,1,1,0} }
Run Code Online (Sandbox Code Playgroud)

那么在将1Byte变量转换为4Byte变量时,或者将unsigned char转换为unsigned int时会发生什么?

Mat*_*lia 6

数值保持不变,因此将零添加到"逻辑"左侧.在构成4字节整数的底层字节中发生的情况取决于平台的字节顺序.