text2binary 1.0.1

Converts a string representation of a hexadecimal number to a Vec<u8>
Documentation
  • Coverage
  • 75%
    3 out of 4 items documented3 out of 3 items with examples
  • Size
  • Source code size: 14.99 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 287.77 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • nogino-sanebou/text2binary
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nogino-sanebou

Overview

Converts a string representation of a hexadecimal number to a Vec<u8>.

Supported are String, Vec<String> and Files.

The string can include spaces and line breaks.

Case insensitive.

Errors

It was not a hexadecimal representation.

Example

String pattern

let text: String = "001234Ab".to_string();
let binary: Vec<u8> = text2binary::convert(&text).unwrap();

// [0x00, 0x12, 0x34, 0xAB]

let text: String = r#"00 12
34 56"#.to_string();
let binary: Vec<u8> = text2binary::convert(&text).unwrap();

// [0x00, 0x12, 0x34, 0x56]

Vec<String> pattern

let lines: Vec<String> = vec!["1234".to_string(), r#"AB
cd"#.to_string(), "".to_string(), "00 00".to_string()];
let binary: Vec<u8> = text2binary::convert_line(&lines).unwrap();

// [0x12, 0x34, 0xAB, 0xCD, 0x00, 0x00]

File pattern

use std::fs::File;

// target.txt
// 00 12 34
// 56 78 AB
// cd Ef 00
let file: File = File::open("target.txt").unwrap();
let binary: Vec<u8> = text2binary::convert_file(&file).unwrap();

// [0x00, 0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]
// target.txt
// cd Ef 00
//
// 56 78 AB
//
// 00 12 34
//
//
let file: File = File::open("target.txt").unwrap();
let binary: Vec<u8> = text2binary::convert_file(&file).unwrap();

// [0xCD, 0xEF, 0x00, 0x56, 0x78, 0xAB, 0x00, 0x12, 0x34]

日本語概要

16進数の文字列表現をバイナリデータ(Vec)に変換します。

String、Vec<String>、Fileに対応しています。

文字列には空白、改行コードも含められます。

大文字と小文字を区別しません。

エラー

16進数表現ではなかった。