我正在尝试将VB.NET代码转换为C代码,但有一些我无法理解的函数,如bitconverter.getbytes()
如果我正确地执行此代码或者我完全错了,请有人看到我的代码并解释我吗?
VB.NET
SetReadFileOffset(NO, MFTCluster * SectperCluster * BytesPerSect)
VB.NET
Private Sub SetReadFileOffset(ByRef NO As System.Threading.NativeOverlapped, ByRef curBig As Int64)
Dim lowoffset() As Byte = BitConverter.GetBytes(curBig)
Dim highoffset As Int32 = BitConverter.ToInt32(lowoffset, 0)
Dim high As Int32
Dim lastbytes(3) As Byte
Array.Copy(lowoffset, 4, lastbytes, 0, 4)
high = BitConverter.ToInt32(lastbytes, 0)
NO.OffsetLow = highoffset
NO.OffsetHigh = high
End Sub
C
setreadfileoffset(overlapped, (sectperclusters * (bytespercluster * MFTCluster)));
C
long endianhextodec(BYTE *buffers, int offs){
BYTE tmp[1] = {0};
if(offs == 0){
tmp[0] = buffers[0];
tmp[1] = buffers[1];
tmp[2] = buffers[2];
tmp[3] = buffers[3];
return tmp[3] << 24;
}
}
void setreadfileoffset(OVERLAPPED overlap, INT64 crbig ){
BYTE *lowoffset = (BYTE*)malloc(sizeof(crbig));
INT32 higoffset = endianhextodec(lowoffset, 0);
INT32 high;
BYTE lastbytes[3];
for(int i = 0; i < 4; i++){
for(int n = 4; n > 0; n--){
lastbytes[i] = lowoffset[n];
}
}
high = endianhextodec(lastbytes, 0);
overlap.Offset = higoffset;
overlap.OffsetHigh = high;
}
答案 0 :(得分:0)
#include <stdint.h>
...
//int64_t curBig = 0x0123456789ABCDEFLL;
int32_t *p = (int32_t *)&curBig;
int32_t highoffset = p[0];//0x89ABCDEF
int32_t high = p[1];//0x01234567