Random 16Bit UUID - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Random 16Bit UUID.php
- <?php
- $hex = bin2hex(random_bytes(16));
- $timeHi = mb_substr($hex, 12, 4);
- $timeHi = hexdec($timeHi) & 0x0fff;
- $timeHi &= ~0xf000;
- $timeHi |= 4 << 12;
- $clockSeqHi = hexdec(mb_substr($hex, 16, 2));
- $clockSeqHi &= 0x3f;
- $clockSeqHi &= ~0xc0;
- $clockSeqHi |= 0x80;
- $id = sprintf(
- '%08s%04s%04s%02s%02s%012s',
- // time low
- mb_substr($hex, 0, 8),
- // time mid
- mb_substr($hex, 8, 4),
- // time high and version
- str_pad(dechex($timeHi), 4, '0', \STR_PAD_LEFT),
- // clk_seq_hi_res
- str_pad(dechex($clockSeqHi), 2, '0', \STR_PAD_LEFT),
- // clock_seq_low
- mb_substr($hex, 18, 2),
- // node
- mb_substr($hex, 20, 12)
- );
- echo $id;
File Description
- Random 16Bit UUID
- PHP Code
- 22 Aug-2022
- 659 Bytes
You can Share it:
Latest PHP Pastes