Last active
August 29, 2015 13:59
-
-
Save triplog/10522254 to your computer and use it in GitHub Desktop.
10進数→32進数(文字列).型の扱いに慣れてないからもっと良い方法があると思う.
This file contains 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
<!doctype html> | |
<?php | |
//とにかく1文字にしたい時 | |
function num2char($input) | |
{ | |
if($input<10) | |
return chr(ord('0') + $input); | |
else | |
return chr(ord('a') + ($input-10)); | |
} | |
//32進数複数桁 | |
function num2x32($input) | |
{ | |
$temp = ""; | |
if($input<32) | |
{ | |
if($input<10) | |
return $temp . chr(ord('0') + $input); | |
else | |
return $temp . chr(ord('a') + ($input-10)); | |
} | |
else | |
{ | |
$temp = num2x32($input/32) . $temp; | |
$temp = $temp . num2x32($input%32); | |
} | |
return $temp; | |
} | |
//戻す場合(一桁) | |
function char2num($input) | |
{ | |
if($input>='a') return ord($input)-ord('a')+10; | |
else return $input; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment