Library code snippets
[C++] Number Base Conversion (binary to octal)
By Mohammad Rastkar, published on 08 Jan 2008
Descriptions & Code
===============< Descriptions >============
-> VSC++ 2005 - Win32 Console App
-> User input a number in binary form, we will print that in octal base. (It's a simple conversion between number bases and will inform you about some helpful C++ standard functions. You can see more infos about the functions in MSDN.)
-> User input a number in binary form, we will print that in octal base. (It's a simple conversion between number bases and will inform you about some helpful C++ standard functions. You can see more infos about the functions in MSDN.)
===============< Code >============
#include <iostream> // system()
using namespace std;
#include <cstdlib> // strtol(), ltoa()
int main()
{
char num_str[50];
cout << "\n Enter a number in binary base, for converting to octal : ";
cin >> num_str;
long num_l = strtol(num_str, NULL, 2); // conversion : binary(char*) -> decimal(long)
ltoa (num_l, num_str, 8); // conversion : decimal(long) -> octal(char*)
cout << "\n Number in octal base : " << num_str << "\n\n";
system("pause");
return 0;
}
Related articles
Related discussion
-
conting repeated words
by Slicksim (2 replies)
-
Can somebody help: CAsyncSOcket class (Client-server networking)
by Mohammad Rastkar (3 replies)
-
custom progress bar in a datagridview with threading
by konikula (1 replies)
-
Calling C++ DLL from C#
by Thushan Fernando (1 replies)
Events coming up
-
Dec
6
Developing AJAX Web Applications with Castle Monorail
London, United Kingdom
Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!
This thread is for discussions of [C++] Number Base Conversion (binary to octal).