写非ASCII字符codeS为二进制文件 [英] Writing non-ASCII character codes to a binary file

查看:135
本文介绍了写非ASCII字符codeS为二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像在Windows 回声-e相当于现有的解决方案?为ASCII 32-126和<$ C的简单方法$ C> CharLib ,这是相当大的,因此不适合小批量文件中包括

The existing solutions like echo -e equivalent in Windows? provide simple methods for ASCII 32-126 and CharLib, which is quite big and thus not fit to include inside a small batch file.

有没有写一个序列的人物重新由十六进制codeS在00-255范围psented像 $ P $ 05 75 9A FF 来一个简单的方法二进制文件?

Is there a simple method to write a sequence of characters represented by hex codes in 00-255 range like 05 75 9a FF to a binary file?

推荐答案

编写非ASCII $ C $ 80 CS-FF是棘手的。我还没有看到一个简单的解决方案之前,所以在这儿呢。

Writing non-ASCII codes 80-FF is tricky. I haven't seen a simple solution before so here it is.

用法:

@echo off
call :writeHex "30 31 32 9F 00 a0 FF" "outputfile.bin"
exit /b

@echo off
call :writeHex 3031329F00a0FF "outputfile.bin"
exit /b

功能:

:writeHex
rem Usage:
rem call :writeHex 3031329F00a0FF "outputfile.bin"
rem call :writeHex "30 31 32 9F 00 a0 FF" "outputfile.bin"
    findstr /r "^[^a-z]*:::" "%~f0" >"%temp%\writebin.vbs"
    cscript //nologo "%temp%\writebin.vbs" "%~1" "%~2"
    del "%temp%\writebin.vbs"
    exit /b

    :::hx = replace(wscript.arguments(0)," ","")
    :::file = wscript.arguments(1)
    :::
    :::length = len(hx)/2 : if length mod 2 then hx = hx & "00"
    :::
    :::s = ""
    :::for i=1 to len(hx) step 4
    :::  s = s & chrW(clng("&H" & mid(hx,i,2)) + clng("&H" & mid(hx,i+2,2)) * 256)
    :::next
    :::
    :::typeBin = 1 : typeText = 2 : bOverwrite = 2
    :::with CreateObject("ADODB.Stream")
    :::  .type = typeText : .open : .writeText s : .saveToFile file, bOverwrite : .close
    :::  .type = typeBin : .open : .loadFromFile file : .position = 2 : data = .read(length)
    :::  .position = 0 : .write data
    :::  .position = length : .setEOS
    :::  .saveToFile file, bOverwrite
    :::  .close
    :::end with

这篇关于写非ASCII字符codeS为二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆