bin2hex(random_bytes())取决于输入多少个字符? [英] How many characters does bin2hex(random_bytes()) depending on input?

查看:213
本文介绍了bin2hex(random_bytes())取决于输入多少个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码为我的应用生成一个简单的UID:

I'm using the following code to genrate a simple UID for my app:

private function _createUid() {
    $bytes = random_bytes(128);
    $uid = bin2hex($bytes);

    return $uid;
}

这样做, _createUid()的结果将为256个字符串。我的问题是,如果在同一台服务器上运行,此字符串是否始终为 256 个字符,我知道不同服务器上的某些区别。另外,一个字节等于两个字符吗?

By doing this, the result of _createUid() will be a 256 character string. My question is, will this string always be 256 characters if run on the same server, I'm aware of some differences on different servers. Also, is one byte equal to two characters?

任何帮助都很好,谢谢!

Any help would be great, thanks!

推荐答案

十六进制始终将一个字节表示为2个字符。

In hex a byte is always expressed as 2 characters.

字节的十六进制表示形式是两个字符对的序列。第一个字符代表字节的最高4位,第二个字符代表字节的最低4位。

Hexadecimal representation of a byte is a sequence of two character pairs. The first character represents the most significant 4 bits and the second character represents the least significant 4 bits of a byte.

这篇关于bin2hex(random_bytes())取决于输入多少个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆