我在这里有点麻烦。
谁能帮我实现一个反转每个字节的解决方案,所以 0xAB 变成 0xBA 但不是“abcd”变成“dcba”。我需要它,所以 AB CD EF 变成 BA DC FE。
最好在 C 或 C++ 中,但它并不重要,只要它可以运行。
到目前为止,我已经在 PureBasic 中实现了一个甚至不起作用的 UBER CRAPPY 解决方案(是的,我知道转换为字符串并返回二进制是一个糟糕的解决方案)。
OpenConsole()
filename$ = OpenFileRequester("Open File","","All types | *.*",0)
If filename$ = ""
End
EndIf
OpenFile(0,filename$)
*Byte = AllocateMemory(1)
ProcessedBytes = 0
Loc=Loc(0)
Repeat
FileSeek(0,Loc(0)+1)
PokeB(*Byte,ReadByte(0))
BitStr$ = RSet(Bin(Asc(PeekS(*Byte))),16,"0")
FirstStr$ = Left(BitStr$,8)
SecondStr$ = Right(BitStr$,8)
BitStr$ = SecondStr$ + FirstStr$
Bit.b = Val(BitStr$)
WriteByte(0,Bit)
ProcessedBytes = ProcessedBytes + 1
ClearConsole()
Print("Processed Bytes: ")
Print(Str(ProcessedBytes))
Loc=Loc(0)
Until Loc = Lof(0)
Delay(10000)
谢谢阅读。