Created
April 2, 2013 20:31
-
-
Save sebastienblanc/5295913 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function invertAndConvert(x){ | |
var e = parseInt(x).toString(2); | |
var bitArray = e.split(""); | |
var convertedString = ""; | |
if(bitArray[0]=="0") { | |
convertedString = convertedString.concat("-"); | |
} | |
else { | |
convertedString = convertedString.concat("r"); | |
} | |
if(bitArray[1]=="0") { | |
convertedString = convertedString.concat("-"); | |
} | |
else { | |
convertedString = convertedString.concat("w"); | |
} | |
if(bitArray[2]=="0") { | |
convertedString = convertedString.concat("-"); | |
} | |
else { | |
convertedString = convertedString.concat("x"); | |
} | |
return convertedString; | |
} | |
function convertModeToString(mode) { | |
var octalString = mode.toString(8); | |
var intArray = octalString.split(""); | |
var result = ""; | |
for (var i=0;i<intArray.length;i++) { | |
result = result.concat(invertAndConvert(intArray[i])); | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment