Writing HEX values back to file
BlitzPlus Forums/BlitzPlus Programming/Writing HEX values back to file
| ||
I have a list of HEX values I want to write back to file. It's sort of working but some values are going missing. It just doesn't make sense to me. The values: 0024 0532 0AF8 10BE I expect an 8-byte file like this: 002405320AF810BE Instead I'm getting an 8-byte file like this: 0024053200001000 As you can see bytes 5, 6 and 8 are missing. Here is my code: Dim mydata$(4) mydata(1) = "0024" mydata(2) = "0532" mydata(3) = "0AF8" mydata(4) = "10BE" saveData() End Function saveData() fn = WriteFile("test.out") For i = 1 To 4 WriteByte fn, hex2dec(Int(Left$(mydata(i),2))) WriteByte fn, hex2dec(Int(Right$(mydata(i),2))) Next CloseFile(fn) End Function Function hex2dec(sValue$) sValue = "$"+ sValue num$ = "0123456789ABCDEFG" sValue = Upper(Mid(sValue, 2)) dec = 0 For i = 1 To Len(sValue) c$ = Mid(sValue, Len(sValue) - (i-1),1) n = Instr(num, c) - 1 dec = dec + n * (16 ^ (i-1)) Next Return dec End Function Is there something I'm missing here? |
| ||
Take out the Int statements to get what you want.WriteByte fn, hex2dec((Left$(mydata(i),2))) WriteByte fn, hex2dec((Right$(mydata(i),2))) |
| ||
D'oh! I can't see the woods for the 1001101000 sometimes. ;) Thanks. |