Usage

./bin2hex 166_TurnItUpPhrVox_01_627a.mp3 1

/* begin binary data: */
char bin_data[] = /* 35065 */
{0xFF,0xFB,0x90,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0x69,0x6E,0x67,0x00,0x00,0x00,0x0F,0x00
//...
,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA
,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA};
/* end binary data. size = 35065 bytes */

Perl source

#!/usr/bin/perl

#
# bin2hex.pl by Chami.com
# http://www.chami.com/tips/
# # number of characters per line
$chars_per_line = 15; # ------------------------------------- # language id
#
# 0 = Perl (default)
# 1 = C / C++
# 2 = Pascal / Delphi
#
$lang = $ARGV[1]; $rem_begin = "begin binary data:";
$rem_end = "end binary data."; # initialize for Perl strings
# by default
$_var = "# $rem_begin\n".
"\$bin_data = # %d\n";
$_begin = "\"";
$_end = "\";\n";
$_break = "\".\n\"";
$_format = "\\x%02X";
$_separator = "";
$_comment = "# $rem_end ".
"size = %d bytes"; # C / C++
if(1 == $lang)
{
$_var = "/* $rem_begin */\n".
"char bin_data[] = ".
"/* %d */\n";
$_begin = "{";
$_end = "};\n";
$_break = "\n";
$_format = "0x%02X";
$_separator = ",";
$_comment = "/* $rem_end ".
"size = %d bytes */";
}
elsif(2 == $lang)
{
$_var = "{ $rem_begin }\n".
"const bin_data : ".
"array [1..%d] of ".
"byte = \n";
$_begin = "(";
$_end = ");\n";
$_break = "\n";
$_format = "\$%02X";
$_separator = ",";
$_comment = "{ $rem_end ".
"size = %d bytes }";
} if(open(F, "<".$ARGV[0]))
{
binmode(F); $s = '';
$i = 0;
$count = 0;
$first = 1;
$s .= $_begin;
while(!eof(F))
{
if($i >= $chars_per_line)
{
$s .= $_break;
$i = 0;
}
if(!$first)
{
$s .= $_separator;
}
$s .= sprintf(
$_format, ord(getc(F)));
++$i;
++$count;
$first = 0;
}
$s .= $_end;
$s .= sprintf $_comment, $count;
$s .= "\n\n"; $s = "\n".sprintf($_var, $count).$s; print $s; close( F );
}
else
{
print
"bin2hex.pl by Chami.com\n".
"\n".
"usage:\n".
" perl bin2hex.pl <binary file>".
" <language id>\n".
"\n".
" <binary file> : path to the ".
"binary file\n".
" <language id> : 0 = Perl, ".
"1 = C/C++/Java, ".
"2 = Pascal/Delphi\n".
"\n";
}

Perl Script to convert binary to hex的更多相关文章

  1. [LeetCode] Convert Binary Search Tree to Sorted Doubly Linked List 将二叉搜索树转为有序双向链表

    Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right pointers ...

  2. Convert Binary Search Tree to Doubly Linked List

    Convert a binary search tree to doubly linked list with in-order traversal. Example Given a binary s ...

  3. LeetCode 426. Convert Binary Search Tree to Sorted Doubly Linked List

    原题链接在这里:https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/ 题目: C ...

  4. 【leetcode】1284. Minimum Number of Flips to Convert Binary Matrix to Zero Matrix

    题目如下: Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the ...

  5. 【LeetCode】426. Convert Binary Search Tree to Sorted Doubly Linked List 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址:https://leetc ...

  6. Convert Binary Search Tree (BST) to Sorted Doubly-Linked List

    (http://leetcode.com/2010/11/convert-binary-search-tree-bst-to.html) Convert a BST to a sorted circu ...

  7. 426. Convert Binary Search Tree to Sorted Doubly Linked List把bst变成双向链表

    [抄题]: Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right po ...

  8. [leetcode]426. Convert Binary Search Tree to Sorted Doubly Linked List二叉搜索树转有序双向链表

    Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right pointers ...

  9. LeetCode426.Convert Binary Search Tree to Sorted Doubly Linked List

    题目 Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right point ...

  10. [Algorithm] 1290. Convert Binary Number in a Linked List to Integer

    Given head which is a reference node to a singly-linked list. The value of each node in the linked l ...

随机推荐

  1. 文心一言 VS 讯飞星火 VS chatgpt (185)-- 算法导论14.1 2题

    二.用go语言,对于图 14-1中的红黑树 T 和关键字 x.key 为35的结点x,说明执行 OS-RANK(T,x) 的过程. 文心一言: 在红黑树中,OS-RANK(T, x) 是一个操作,用于 ...

  2. SpringBoot3集成Zookeeper

    标签:Zookeeper3.8 ,Curator5.5: 一.简介 ZooKeeper是一个集中的服务,用于维护配置信息.命名.提供分布式同步.提供组服务.分布式应用程序以某种形式使用所有这些类型的服 ...

  3. Python Code_06基础篇

    条件表达式 # coding:utf-8 # author : 写bug的盼盼 # development time : 2021/8/28 7:38 num_a = input('请输入第一个整数' ...

  4. SpringMVC01——回顾MVC

    1.1什么是MVC MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范. 是将业务逻辑.数据.显示分离的方法来组织代码. MVC主要作用是降低了视图 ...

  5. 痞子衡嵌入式:我拿到了2023年度电子星球(eestar)年度黑马作者

    今天收到了「电源网旗下电子星球」 颁发的 2023 年度黑马作者奖牌,这是痞子衡继 2019 年和与非网合作后的第二个媒体平台颁发的奖项.这个奖牌做得很有质感,拿在手里沉甸甸的.此外与奖牌配套的还有一 ...

  6. [转帖]TPC-C 、TPC-H和TPC-DS区别

    https://zhuanlan.zhihu.com/p/339886289 针对数据库不同的使用场景TPC组织发布了多项测试标准. TPC-C: TPC Benchmark C于1992年7月获得批 ...

  7. [转帖]sqluldr2 oracle直接导出数据为文本的小工具使用

    https://www.cnblogs.com/ocp-100/p/11098373.html 近期客户有需求,导出某些审计数据,供审计人进行核查,只能导出成文本或excel格式的进行查看,这里我们使 ...

  8. GS7 备份恢复之后客户端登录报错的解决方法:COM 类工厂中 CLISID 为 xxxx的组建失败, 原因是出现了一下错误 8000401a

    1. 最近需要创建一个用户的数据库应用信息, 备份恢复之后发现有时候一些环境无法使用. COM 类工厂中 CLISID 为 xxxx的组建失败, 原因是出现了一下错误 8000401a 错误图片为 2 ...

  9. postman中js脚本简单用法

    1.获取接口相应结果 var jsonData = pm.response.json() 2.设置环境变量 pm.environment.set("variable_key", & ...

  10. ClickHouse(06)ClickHouse建表语句DDL详细解析

    目录 当前服务器上创建表(单节点) 语法形式 使用显式架构 从相同结构的表复制创建 从表函数创建 从选择查询创建 分布式集群创建表 临时表 分区表 创建表语句关键字解析 空值或非空修饰符 默认值表达式 ...