c与cpp输出16进制,8进制及ASCII

1.c

#include <stdio.h>
int main(int argc,char **argv)
{
	for(int i=0;i<=127;i++)
	{
		printf("%X-%03o-%c\n",i,i,i);
	}
	return 0;
}

2.cpp

#include <iostream>
#include <iomanip>

using namespace std;

int main(int argc,char **argv)
{
	for(int i=0;i<=127;i++)
	{
		cout<<setw(2)<<setfill('0')<<hex<<i<<"-"<<setw(3)<<setfill('0')<<oct<<i<<"-"<<dec<<(char)i<<endl;
	}

	return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*