b/C + + binary, octal, decimal, and hexadecimal representations

Source: Internet
Author: User
Tags bitset

the three types of input that the C + + language itself supports are:
1. Decimal. such as 56.
2.16 binary, starting with 0x, such as 0x7a. Output hexadecimal hex keyword formatting, such as cout<3. Eight binary, starting with 0, for example 030. The output octal is formatted with the OCT keyword, such as cout<<oct<<12.


The following sample program:

#include <iostream>
using namespace std;
void Main ()
{
	int a,b,c;
	a=10; Decimal
	b=010;//octal
	c=0x10//16
	cout<< "A=" <<a<<endl;
	cout<< "b=" <<b<<endl;
	cout<< "c=" <<c<<endl;
	cout<< "A (octal) =" <<oct<<a<<endl;
	cout<< "a (hexadecimal) =" <
#include <bitset>
#include <iostream>
int main ()
{
	int c=-1;
	std::bitset<sizeof (int) *8> A (c); 
	std::cout<<a<< "\ n";
	return 0;
}


Bitset usage:



Reproduced from: http://www.zhiwenweb.cn/Category/Learning/1228.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.