Perl Script to convert binary to hex
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的更多相关文章
- [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 ...
- 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 ...
- 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 ...
- 【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 ...
- 【LeetCode】426. Convert Binary Search Tree to Sorted Doubly Linked List 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址:https://leetc ...
- 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 ...
- 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 ...
- [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 ...
- 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 ...
- [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 ...
随机推荐
- JS - HTML精确定位
scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离 scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最 ...
- SpringMVC02——第一个MVC程序-配置版(low版)
配置版 新建一个子项目,添加Web支持![在MVC01中有详细方法] 确定导入了SpringMVC的依赖 配置web.xml,注册DispatcherServlet <?xml version= ...
- Go-数据类型-布尔类型-bool
布尔类型--bool 只有两个值 true false 不能转换成其他类型,也不能参加数值运算 布尔应用场景 if swicht for 三大分支语句中的条件部分 比较运算和逻辑运算的返回值 作为通道 ...
- ingress nginx 支持的K8S版本以及nginx版本信息
- [转帖]【oracle】oracle查询表存储大小和表空间大小
目录 查看表分配的物理空间大小 查看表实际存储空间大小 查看每个表空间的大小 查看表空间大小及使用率 查看数据库中数据文件信息 查看临时表空间信息 oracle表大小有两种含义,即表分配的空间大小和实 ...
- [转帖]echo “新密码”|passwd --stdin 用户名
https://www.cnblogs.com/rusking/p/6912809.html --stdin This option is used to indicate that passwd s ...
- [转帖]vm内核参数之缓存回收drop_caches
注:本文分析基于3.10.0-693.el7内核版本,即CentOS 7.4 1.关于drop_caches 通常在内存不足时,我们习惯通过echo 3 > /proc/sys/vm/drop_ ...
- [转帖]查看x86 cpu睿频命令
查看cpu是否开启睿频,offline掉一些cpu核心后,查看cpu睿频是否升高? turbostat统计X86 处理器的频率.空闲状态.电源状态.温度等状态等 [root@rootbird~]# t ...
- 基于Seata探寻分布式事务的实现方案
作者:京东物流技术与数据智能部 张硕 1 背景知识 随着业务的快速发展.业务复杂度越来越高,几乎每个公司的系统都会从单体走向分布式,特别是转向微服务架构.随之而来就必然遇到分布式事务这个难题,这篇文章 ...
- js中计算一个时间点加上一个时间段后的时间
function aa(a,b){ console.log(111,a,b) var nd = new Date(Date.parse(a.replace(/-/g, "/"))) ...