JavaScript decoct
Returns a string containing an octal representation of the given number
1 2 3 4 56 7 8 9 1011 12 13 14 1516 17 18 | function decoct (number) { // Returns a string containing an octal representation of the given number // // version: 909.322 // discuss at: http://phpjs.org/functions/decoct // + 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); } |
Examples
» Example 1
Running
1 | decoct(15); |
Should return
1 | '17' |
» Example 2
Running
1 | decoct(264); |
Should return
1 | '410' |
Dependencies
No dependencies, you can use this function standalone.
Open syntax issues
php.js uses JsLint to help us keep our code consistent and prevent some common bugs.
Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.
Authors
Thanks to the following developers, you get to have decoct goodness in JavaScript.

decoct('8') does not work correctly. A fix:


Kevin van Zonneveld
6 Oct '08