将剩余字节的填充添加到十六进制字符串 [英] Add padding to hex string for remaining bytes
本文介绍了将剩余字节的填充添加到十六进制字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从来没有在PHP中使用Hex-strings(或任何语言)。现在我想知道如何将填充添加到以十六进制表示的十六进制字符串中,直到它达到8个字节。
$ hex = bin2hex(MAIN);
如何为其余的 00
添加字节,以便 $ hex
包含8个字节?
$ hex = str_pad(bin2hex(MAIN),16,'00',STR_PAD_LEFT);
输出:000000004d41494e
这就是你想要的吗?
I never ever worked with Hex-strings in PHP (or whatever language). Now I'm wondering how I could add padding to a hex string with 00 (in hex) up until it reaches 8 bytes.
$hex = bin2hex("MAIN");
How can I add 00
for the remaining bytes so that $hex
holds 8 bytes?
解决方案
Maybe try str_pad :
$hex = str_pad(bin2hex("MAIN"), 16, '00', STR_PAD_LEFT);
Output : "000000004d41494e"
Is that what you want ?
这篇关于将剩余字节的填充添加到十六进制字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文