Can anyone help me to convert from binnary to octal or hexadecimal in c++??
Lotus_2011 0 Light Poster
Recommended Answers
Jump to Post— Radical Edward 301#include <iostream> #include <iomanip> #include <string> #include <bitset> int main() { std::cout << "Enter a binary number: "; std::string bin; if (getline(std::cin, bin)) { std::bitset<32> bits(bin); std::cout << std::oct << bits.to_ulong() << '\n'; std::cout << std::hex << bits.to_ulong() << '\n'; } }
All 4 Replies
Radical Edward 301 Posting Pro
Lotus_2011 0 Light Poster
William Hemsworth 1,339 Posting Virtuoso
Lotus_2011 0 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.