我正在执行以下代码以从数组中读取 6 字节的特定值。对我来说,以下内容看起来很丑。我在 Little Endian 处理器上运行此代码。有什么方法可以让它更优雅。
temp_ts = (ptr[ts_offset]);
new_ts = temp_ts << 40;
temp_ts = (ptr[ts_offset + 1]);
new_ts |= temp_ts << 32;
temp_ts = (ptr[ts_offset + 2]);
new_ts |= temp_ts << 24;
temp_ts = (ptr[ts_offset + 3]);
new_ts |= temp_ts << 16;
temp_ts = (ptr[ts_offset + 4]);
new_ts |= temp_ts << 8;
temp_ts = (ptr[ts_offset + 5]);
new_ts |= temp_ts << 0;
注意:代码运行良好。这只是样式问题。