UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

72 lines (60 loc) 1.98 kB
--- layout: page title: "JavaScript decoct function" comments: true sharing: true footer: true alias: - /functions/view/decoct:383 - /functions/view/decoct - /functions/view/383 - /functions/decoct:383 - /functions/383 --- <!-- Generated by Rakefile:build --> A JavaScript equivalent of PHP's decoct {% codeblock math/decoct.js lang:js https://raw.github.com/kvz/phpjs/master/functions/math/decoct.js raw on github %} function decoct (number) { // From: http://phpjs.org/functions // + original by: Enrique Gonzalez // + bugfixed by: Onno Marsman // + improved by: http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript // + input by: pilus // * example 1: decoct(15); // * returns 1: '17' // * example 2: decoct(264); // * returns 2: '410' if (number < 0) { number = 0xFFFFFFFF + number + 1; } return parseInt(number, 10).toString(8); } {% endcodeblock %} - [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/math/decoct.js) Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are the closest match to this hashtable-like data structure. Please also note that php.js offers community built functions and goes by the [McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just: - [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/math/decoct.js) ### Example 1 This code {% codeblock lang:js example %} decoct(15); {% endcodeblock %} Should return {% codeblock lang:js returns %} '17' {% endcodeblock %} ### Example 2 This code {% codeblock lang:js example %} decoct(264); {% endcodeblock %} Should return {% codeblock lang:js returns %} '410' {% endcodeblock %} ### Other PHP functions in the math extension {% render_partial _includes/custom/math.html %}