Last active
December 15, 2015 08:19
-
-
Save kahagon/5229524 to your computer and use it in GitHub Desktop.
greeting!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $greeting = [0xE4BB8A, 0xE697A5, 0xE381AF, 0xE38081, 0xE38184, 0xE3818B, 0xE3818C, 0xE3818A, 0xE38199, 0xE38194, 0xE38197, 0xE381A7, 0xE38197, 0xE38287, 0xE38186, 0xE3818B, 0xEFBC9F]; | |
| foreach ($greeting as $v) { | |
| print int2bin($v); | |
| } | |
| print PHP_EOL; | |
| function int2bin($i) { | |
| $byte_array = null; | |
| $byte_len = ceil(bitlen($i)/8); | |
| for ($j = 0; $j < $byte_len; $j++) { | |
| $var = ($i & 1<<(($j*8)+0)) | |
| | ($i & 1<<(($j*8)+1)) | |
| | ($i & 1<<(($j*8)+2)) | |
| | ($i & 1<<(($j*8)+3)) | |
| | ($i & 1<<(($j*8)+4)) | |
| | ($i & 1<<(($j*8)+5)) | |
| | ($i & 1<<(($j*8)+6)) | |
| | ($i & 1<<(($j*8)+7)); | |
| $var >>= ($j*8); | |
| $byte_array = pack("C", $var) . $byte_array; | |
| } | |
| return $byte_array; | |
| } | |
| function bitlen($i, $l = 0) { | |
| return $i < pow(2, $l) ? $l : bitlen($i, ++$l); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment