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. 【RTOS】基于RTOS的嵌入式系统看门狗策略

    RTOS - high integrity systems 看门狗策略 Watchdog Strategies for RTOS enabled embedded systems 介绍 看门狗定时器就 ...

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

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

  3. 2023 SHCTF-校外赛道 PWN WP

    WEEK1 nc 连接靶机直接梭 hard nc 同样是nc直接连,但是出题人利用linux命令的特性,将部分flag放在了特殊文件中 利用ls -a查看所有文件,查看.gift,可以得到前半段 然后 ...

  4. 【特别的骚气】asp.net core运行时注入服务,实现类库热插拔

    引言 很久之前在群里有看到说asp.net core能不能在运行时注入程序,当时并没有太在意,刚才在某个群里又看到有人再问,core能不能在运行时注入服务,闲来无事,我就研究了一下,其实也比较简单,在 ...

  5. 重写SpringCloudGateway路由查找算法,性能提升100倍!

    如果你也在做SpringCloudGateway网关开发,希望这篇文章能给你带来一些启发 背景 先说背景,某油项目,通过SpringCloudGateway配置了1.6万个路由规则,实际接口调用过程中 ...

  6. [转帖]TiDB系统调参实战经验

    https://tidb.net/blog/c9466c40#TiDB%E7%B3%BB%E7%BB%9F%E8%B0%83%E5%8F%82%E5%AE%9E%E6%88%98%E7%BB%8F%E ...

  7. [转帖]总结:shell中的if条件判断

    一.if 的基本语法 if [ command ];then xxx elif [ command ];then xxx else xxx fi 二.常见的一些写法案例 1.if [ "x$ ...

  8. CPU算力提升与实际性能提升的关系

    关于SPEC2006CPU和RedisBenchmark的理解 最近研究过硬件CPU的性能和Redis这样单线程重IO服务 突然想对比一下CPU算力提升占Redis性能提升的比率情况 性能很大程度由C ...

  9. [转帖]Nginx 性能测试

    https://plantegg.github.io/2022/10/10/Nginx%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95/ 压测工具选择 wrk ,apache ...

  10. 银河麒麟v10 安装 virt-manager 的过程

    上个月公司购置一台飞腾2000+ 银河麒麟v10的机器. 想着能够利用虚拟化 安装一下虚拟机 提高测试灵活度 找了一下原厂要了一下相关的命令 在这里进行一下测试工作. 第一步: 安装必备的包 yum ...