Skip to content

Instantly share code, notes, and snippets.

@triplog
Last active August 29, 2015 13:59
Show Gist options
  • Save triplog/10522254 to your computer and use it in GitHub Desktop.
Save triplog/10522254 to your computer and use it in GitHub Desktop.
10進数→32進数(文字列).型の扱いに慣れてないからもっと良い方法があると思う.
<!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