|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『楼 主』:
16进制字符文本/二进制文件迷你互转器
使用 LLM 解释/回答一下
为解决一个网友的问题刚写的,16进制字符文本/二进制文件迷你互转器
(由于带有回车换行选择性处理的开关,加上0D 0A可以是要处理的二进制数据,也可以是回车换行,所以虽说是小意思,但写的过程中还是颇费一些心思的。。)
对学习字符,数值处理很有帮助的。。。
加了,简单的输入检测和帮助
更新了。
Last edited by GOTOmsdos on 2006-7-20 at 21:36 ]
A mini converter for hexadecimal character text/binary file mutual conversion that I just wrote to solve a netizen's problem.
(Because there is a switch for selective processing of carriage return and line feed, and 0D 0A can be either binary data to be processed or carriage return and line feed, so although it's a small thing, it took some thought during writing..)
It's very helpful for learning character and numerical processing...
Added simple input detection and help.
Updated.
Last edited by GOTOmsdos on 2006-7-20 at 21:36 ]
附件
1: txt_bin.rar (2006-7-19 21:19, 35 KiB, 下载附件所需积分 1 点
,下载次数: 459)
|
|
2006-7-18 15:14 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
bin2txt不对了,第二个0的16进制显示应该是30,转换后变为了
Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
00000000 30 00 31 31 32 32 33 33 34 34 35 35 36 36 37 37 0.11223344556677
00000010 38 38 39 39 61 61 62 62 63 63 64 64 65 65 66 66 8899aabbccddeeff
00000020 30 00 31 31 32 32 33 33 34 34 35 35 36 36 37 37 0.11223344556677
00000030 38 38 39 39 61 61 62 62 63 63 64 64 65 65 66 66 8899aabbccddeeff
00000040 30 00 31 31 32 32 33 33 34 34 35 35 36 36 37 37 0.11223344556677
00000050 38 38 39 39 61 61 62 62 63 63 64 64 65 65 66 66 8899aabbccddeeff
00000060 30 00 31 31 32 32 33 33 34 34 35 35 36 36 37 37 0.11223344556677
00000070 38 38 39 39 61 61 62 62 63 63 64 64 65 65 66 66 8899aabbccddeeff
00000080 30 00 31 31 32 32 33 33 34 34 35 35 36 36 37 37 0.11223344556677
00000090 38 38 39 39 61 61 62 62 63 63 64 64 65 65 66 66 8899aabbccddeeff
000000A0 30 00 31 31 32 32 33 33 34 34 35 35 36 36 37 37 0.11223344556677
000000B0 38 38 39 39 61 61 62 62 63 63 64 64 65 65 66 66 8899aabbccddeeff
而且A、B、C、D、E、F均应该为大写
应该已换行的0D0A作为主要的换行符号(我需要一个直接将BIN转为TXT的,不用删除里面的0D0A换行符号,用0D0A换行符号作为分段识别标志)
我用UPXShell加密压缩了TXT2BIN一下,减小到17.5k,在命令提示符可以正常使用^_^
Last edited by zxcv on 2006-7-18 at 16:31 ]
The bin2txt is incorrect. The hexadecimal display of the second 0 should be 30, but after conversion it becomes
Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
00000000 30 00 31 31 32 32 33 33 34 34 35 35 36 36 37 37 0.11223344556677
00000010 38 38 39 39 61 61 62 62 63 63 64 64 65 65 66 66 8899aabbccddeeff
00000020 30 00 31 31 32 32 33 33 34 34 35 35 36 36 37 37 0.11223344556677
00000030 38 38 39 39 61 61 62 62 63 63 64 64 65 65 66 66 8899aabbccddeeff
00000040 30 00 31 31 32 32 33 33 34 34 35 35 36 36 37 37 0.11223344556677
00000050 38 38 39 39 61 61 62 62 63 63 64 64 65 65 66 66 8899aabbccddeeff
00000060 30 00 31 31 32 32 33 33 34 34 35 35 36 36 37 37 0.11223344556677
00000070 38 38 39 39 61 61 62 62 63 63 64 64 65 65 66 66 8899aabbccddeeff
00000080 30 00 31 31 32 32 33 33 34 34 35 35 36 36 37 37 0.11223344556677
00000090 38 38 39 39 61 61 62 62 63 63 64 64 65 65 66 66 8899aabbccddeeff
000000A0 30 00 31 31 32 32 33 33 34 34 35 35 36 36 37 37 0.11223344556677
000000B0 38 38 39 39 61 61 62 62 63 63 64 64 65 65 66 66 8899aabbccddeeff
And A, B, C, D, E, F should all be in uppercase
The 0D0A that should have been wrapped should be used as the main line break symbol (I need one that directly converts BIN to TXT, without deleting the 0D0A line break symbol inside, using the 0D0A line break symbol as the segment identification mark)
I used UPXShell to encrypt and compress TXT2BIN, reducing it to 17.5k, and it can work normally in the command prompt ^_^
Last edited by zxcv on 2006-7-18 at 16:31 ]
|
|
2006-7-18 15:52 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
修改了。。。现在把字符弄成大写。。
Last edited by GOTOmsdos on 2006-7-18 at 17:42 ]
Modified... Now make the characters uppercase.
Last edited by GOTOmsdos on 2006-7-18 at 17:42 ]
|
|
2006-7-18 17:39 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
|
2006-7-18 17:57 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
文本:
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
txt2bin转换为bin后没问题
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
但是再把这个bin用bin2txt转换为txt后,txt就不正确了,因该是判断数据出问题(0X只能识别为X)
Last edited by zxcv on 2006-7-18 at 21:10 ]
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
010102030405060708090A0B0C0D0E0F
After converting txt2bin to bin, there is no problem.
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
01 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
But when converting this bin back to txt using bin2txt, the txt is incorrect. It should be that there is a problem with data judgment (0X can only be recognized as X).
Last edited by zxcv on 2006-7-18 at 21:10 ]
|
|
2006-7-18 21:08 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
0X只能识别为X ?
16进制 没有 0X 啊
我测试都没有问题,你检查一下,字符
Last edited by GOTOmsdos on 2006-7-18 at 22:18 ]
0X can only be recognized as X?
There is no 0X in hexadecimal.
I tested and there is no problem, you check it, character
Last edited by GOTOmsdos on 2006-7-18 at 22:18 ]
|
|
2006-7-18 21:54 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
你把出错的东西帖出来,
You post the things that went wrong.
|
|
2006-7-18 22:02 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
哦,我发现了,在BIN2TXT中,我把0D 0A分开处理了
这样有问题了
我改一下;;
Last edited by GOTOmsdos on 2006-7-18 at 22:20 ]
Oh, I found out that in BIN2TXT, I handled 0D 0A separately. There's a problem with this. I'll make a change.
Last edited by GOTOmsdos on 2006-7-18 at 22:20 ]
|
|
2006-7-18 22:09 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
你就直接使用文本1.txt:
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
和
BAT:
@echo off
txt2bin 1.txt 1.bin
bin2txt 1.bin 2.txt
试验就知道了
正确的2.txt是:
000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F
注:
txt2bin不需要考虑将0D0A换行符转换入bin(TXT转BIN后,BIN内不需要保留回车换行,最后一个制作的txt2bin程序你加入了0D0A,这个不用(下午三点那个正常)),0D0A换行符在txt2bin后生成的BIN里没有意义
而bin2txt的BIN转TXT后,如果BIN数据里有0D0A换行符,则转换为TXT后需要换行(这个BIN文件不是txt2bin生成的,所以里面有可能包含0D0A换行符)
其实就是:txt2bin不需要考虑0D0A换行符,只把字符写入BIN;bin2txt需要考虑BIN的0D0A换行符换行(可以考虑加开关参数是否忽略0D0A换行符)
Last edited by zxcv on 2006-7-18 at 23:53 ]
You directly use text 1.txt:
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
000102030405060708090A0B0C0D0E0F
And
BAT:
@echo off
txt2bin 1.txt 1.bin
bin2txt 1.bin 2.txt
You'll know when you test it.
The correct 2.txt is:
000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F
Note:
For txt2bin, there's no need to consider converting 0D0A line breaks into the bin (after TXT is converted to BIN, there's no need to retain carriage returns and line feeds in the BIN; the last txt2bin program you made included 0D0A, which is not needed (the one at three o'clock in the afternoon is normal)), and 0D0A line breaks have no meaning in the BIN generated after txt2bin.
And for bin2txt, after BIN is converted to TXT, if there are 0D0A line breaks in the BIN data, they need to be converted to line breaks in the TXT (this BIN file was not generated by txt2bin, so it may contain 0D0A line breaks).
Actually, it's: txt2bin doesn't need to consider 0D0A line breaks, just write the characters into the BIN; bin2txt needs to consider 0D0A line breaks in the BIN to create line breaks in the TXT (a switch parameter can be considered to ignore 0D0A line breaks).
Last edited by zxcv on 2006-7-18 at 23:53 ]
|
|
2006-7-18 22:33 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
改好了,你去下吧。。。
It's fixed. You can go and download it...
|
|
2006-7-19 00:03 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
现在我都保留了回车换行符了。
因为,这样才可以互转,互相还原的,
转成BIN,如果没有了换行符,就不能还原成TXT了。。
如果你不保留,就用上次传的吧。。
Now I have all retained the carriage return and line feed characters.
Because, only in this way can mutual conversion and mutual restoration be achieved.
When converted to BIN, if there are no line feed characters, it cannot be restored to TXT.
If you don't retain them, just use the one uploaded last time.
|
|
2006-7-19 00:12 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
我认为应该增加一个开关参数,用来打开/关闭换行符号是否使用(默认打开)
非常感谢GOTOmsdos的帮助
Last edited by zxcv on 2006-7-19 at 09:18 ]
I think a switch parameter should be added to turn on/off whether line breaks are used (default is on)
Thanks a lot for GOTOmsdos's help
Last edited by zxcv on 2006-7-19 at 09:18 ]
|
|
2006-7-19 02:30 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
那我就加这个功能吧。。等一下更新。。
Then I'll add this function.. Wait for the update..
|
|
2006-7-19 12:00 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
bin2txt开关参数最好设置为3种:
1、默认打开:有0D0A换行符换行
2、关闭参数:忽略0D0A换行符不换行
3、直写:直接把0D0A换行符原样写成字符(16进制的数据全部写入,可以用来做数据分段参考符号)
The switch parameters of bin2txt are best set to 3 types:
1. Default on: Newline with 0D0A line feed characters
2. Off parameter: Ignore 0D0A line feed characters and do not wrap lines
3. Direct write: Directly write 0D0A line feed characters as original characters (all hexadecimal data is written, which can be used as a reference symbol for data segmentation)
|
|
2006-7-19 14:53 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
已经更新了:
1 没有参数,保留回车换行
2 /killline 驱除回车换行
3 n 每隔n对16进制字符就添加换行
你说的
“直写:直接把0D0A换行符原样写成字符(16进制的数据全部写入,可以用来做数据分段参考符号)”
这个与大多数的用法不兼容。。
Has been updated:
1 No parameters, keep carriage return and line feed
2 /killline Remove carriage return and line feed
3 n Add a line feed every n hexadecimal characters
What you said
"Direct writing: directly write the 0D0A line feed character as it is (all hexadecimal data is written, which can be used as a data segmentation reference symbol)"
This is incompatible with most usages.
|
|
2006-7-19 15:20 |
|