China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-22 23:09
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » Mini Converter between Hexadecimal Character Text/Binary File View 26,657 Replies 104
Original Poster Posted 2006-07-18 15:14 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
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 ]
Attachments
txt_bin.rar (35 KiB, Credits to download 1 pts, Downloads: 462)
Floor 2 Posted 2006-07-18 15:52 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
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 ]
Floor 3 Posted 2006-07-18 17:39 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
Modified... Now make the characters uppercase.

[ Last edited by GOTOmsdos on 2006-7-18 at 17:42 ]
Floor 4 Posted 2006-07-18 17:57 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
It's done, go download it.
Floor 5 Posted 2006-07-18 21:08 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
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 ]
Floor 6 Posted 2006-07-18 21:54 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
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 ]
Floor 7 Posted 2006-07-18 22:02 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
You post the things that went wrong.
Floor 8 Posted 2006-07-18 22:09 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
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 ]
Floor 9 Posted 2006-07-18 22:33 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
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 ]
Floor 10 Posted 2006-07-19 00:03 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
It's fixed. You can go and download it...
Floor 11 Posted 2006-07-19 00:12 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
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.
Floor 12 Posted 2006-07-19 02:30 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
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 ]
Floor 13 Posted 2006-07-19 12:00 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
Then I'll add this function.. Wait for the update..
Floor 14 Posted 2006-07-19 14:53 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
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)
Floor 15 Posted 2006-07-19 15:20 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
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.
1 2 3 7 Next ›
Forum Jump: