
Octal numbers are a base-8 numbering system often used in low-level programming, file permissions (especially in linux), and data encoding.
In this guide, you'll learn how to convert octal numbers into binary, hexadecimal, decimal, and string formats using Python, JavaScript, C#, Java, and C++ with easy, working examples.
If you want to skip the code and experiment instantly, try DevGizmo's Octal Converter - a free, browser-based tool that converts between octal, binary, hexadecimal, and decimal in real time.
The octal system (base-8) uses 0-7 digits. Each octal digit represents three binary bits.
Example:
Octal: 12
Binary: 1010
Decimal: 10
Python's int() and built-in formatting functions make base conversions simple.
Octal to Decimal
octal = "12"
decimal = int(octal, 8)
print(decimal) # Output: 10
Octal to Binary
binary = bin(int(octal, 8))
print(binary) # Output: 0b1010
Octal to Hexadecimal
hexadecimal = hex(int(octal, 8))
print(hexadecimal) # Output: 0xa
Octal to String (Text)
octal_text = ["110", "145", "154", "154", "157"] # 'Hello' in octal ASCII
string = ''.join(chr(int(oct_char, 8)) for oct_char in octal_text)
print(string) # Output: Hello
JavaScript's parseInt() and toString() handle base conversions easily.
Octal to Decimal
let octal = "12";
let decimal = parseInt(octal, 8);
console.log(decimal); // 10
Octal to Binary
let binary = parseInt(octal, 8).toString(2);
console.log(binary); // 1010
Octal to Hexadecimal
let hex = parseInt(octal, 8).toString(16);
console.log(hex); // a
Octal to String (Text)
function octalArrayToString(arr) {
return arr.map(oct => String.fromCharCode(parseInt(oct, 8))).join('');
}
console.log(octalArrayToString(["110", "145", "154", "154", "157"])); // Hello
C#'s Convert.ToInt32() and ToString() make conversions simple.
Octal to Decimal
string octal = "12";
int decimalValue = Convert.ToInt32(octal, 8);
Console.WriteLine(decimalValue); // 10
Octal to Binary
string binary = Convert.ToString(Convert.ToInt32(octal, 8), 2);
Console.WriteLine(binary); // 1010
Octal to Hexadecimal
string hex = Convert.ToInt32(octal, 8).ToString("X");
Console.WriteLine(hex); // A
Octal to String (Text)
string[] octals = { "110", "145", "154", "154", "157" };
string text = string.Join("", octals.Select(o => (char)Convert.ToInt32(o, 8)));
Console.WriteLine(text); // Hello
Java provides Integer.parseInt() for base conversion and toString() for reformatting.
Octal to Decimal
String octal = "12";
int decimalValue = Integer.parseInt(octal, 8);
System.out.println(decimalValue); // 10
Octal to Binary
String binary = Integer.toBinaryString(Integer.parseInt(octal, 8));
System.out.println(binary); // 1010
Octal to Hexadecimal
String hex = Integer.toHexString(Integer.parseInt(octal, 8));
System.out.println(hex); // a
Octal to String (Text)
String[] octals = {"110", "145", "154", "154", "157"};
StringBuilder sb = new StringBuilder();
for (String oct : octals) {
sb.append((char) Integer.parseInt(oct, 8));
}
System.out.println(sb.toString()); // Hello
C++ provides standard methods in std::stoul and std:stringstream.
Octal to Decimal
#include <iostream>
#include <string>
int main() {
std::string octal = "12";
unsigned long decimal = std::stoul(octal, nullptr, 8);
std::cout << "Decimal: " << decimal << std::endl;
}
Octal to Binary
#include <iostream>
#include <bitset>
#include <string>
int main() {
std::string octal = "12";
unsigned long decimal = std::stoul(octal, nullptr, 8);
std::bitset<16> binary(decimal);
std::cout << "Binary: " << binary.to_string().substr(binary.to_string().find('1')) << std::endl;
}
Octal to Hexadecimal
#include <iostream>
#include <sstream>
#include <string>
int main() {
std::string octal = "12";
unsigned long decimal = std::stoul(octal, nullptr, 8);
std::stringstream ss;
ss << std::hex << std::uppercase << decimal;
std::cout << "Hex: " << ss.str() << std::endl;
}
Octal to String (Text)
#include <iostream>
#include <string>
#include <vector>
int main() {
std::vector<std::string> octals = {"110", "145", "154", "154", "157"};
std::string text;
for (const auto& oct : octals) {
char ch = static_cast<char>(std::stoul(oct, nullptr, 8));
text += ch;
}
std::cout << "String: " << text << std::endl;
}
Octal to Binary: Bit-level visualisation and debugging
Octal to Decimal: Numeric calculations
Octal to Hexadecimal: Low-level data encoding
Octal to String (Text): ASCII or text interpretation
You can convert between Octal, Binary, Hex, Decimal, and even String instantly using DevGizmo's Octal Converter. It's fast, accurate, and entierly client-side, perfect for quick conversions while coding.
Octal numbers bridge the gap between binary and human-readable representations. Understanding how to convert between octal, binary, decimal, and hexadecimal is essential for debugging, encoding, and system programming.
With these examples in Python, JavaScript, C#, Java, and C++, you can handle any octal conversions with confidence - or try DevGizmo's Octal Converter for instant results.
Learn to convert octan numbers into binary, hexadecimal, decimal, and string formats in Python, JavaScript, C#, Java, and C++. This detailed guide includes working code examples for each conversion and shows where each format is used. Try conversions instantly with DevGizmo's Octal Converter.