CakeFest 2024: The Official CakePHP Conference

octdec

(PHP 4, PHP 5, PHP 7, PHP 8)

octdec8 進数を 10 進数に変換する

説明

octdec(string $octal_string): int|float

octal_string により指定された 8 進数を 10 進数表現した数値を返します。

パラメータ

octal_string

変換したい 8 進文字列。 octal_string に無効な文字を与えても、静かに無視されます。 PHP 7.4.0 以降では、無効な文字を与えることは推奨されません。

戻り値

octal_string を 8 進で表した値を返します。

変更履歴

バージョン 説明
7.4.0 無効な文字を与えると、非推奨の警告が出るようになりました。 結果は不正な文字がなかったかのように計算されます。

例1 octdec() の例

<?php
echo octdec('77') . "\n";
echo
octdec(decoct(45));
?>

上の例の出力は以下となります。

63
45

注意

注意:

この関数は、プラットフォームの int 型に収まらない大きな数も変換できます。 その場合、結果は float で返します。

参考

  • decoct() - 10 進数を 8 進数に変換する
  • bindec() - 2 進数 を 10 進数に変換する
  • hexdec() - 16 進数を 10 進数に変換する
  • base_convert() - 数値の基数を任意に変換する

add a note

User Contributed Notes 3 notes

up
2
Anonymous
21 years ago
The 'S' flag for Unix file access rights is badly computed in the above sample.
If the corresponding 'x' bit (exec) is not set, and the 's' bit (setgid/setuid/sticky) is set, then the flag should not be displayed as and uppercase 'S', but as a lower case 's'. Also the sticky bit (mainly used for folders with public right access rights such as /tmp to protect against deletion by non owner) is badly named ("text"?).
up
2
contato at andersonfraga dot net
15 years ago
Number is octal?

Simple and easy:

<?php

function is_octal($x) {
return
decoct(octdec($x)) == $x;
}

echo
is_octal(077); // true
echo is_octal(195); // false

?>

Thanks
[]'s
up
0
harry at disgruntledgoat dot com
17 years ago
Calling the sticky bit "text" is not erroneous: On UNIX back in 1974, it instructed the operating system to retain the text segment of the program in swap space after the process exited. This speeded subsequent executions by allowing the kernel to make a single operation of moving the program from swap to real memory.
To Top