十进制转十六进制
8位char和16位short十六进制输出格式分别为%hhx,%hx
32位int和64位longlong十六进制输出格式分别为%x,%llx
8位char型
Input an integer and it's type. such as
127 char
outout the two's complement of them.
7fH
#include <bits/stdc++.h>
using namespace std;
int main() {
long long num;
string st;
while(scanf("%lld",&num)!=-1){
cin>>st;
if(st=="char") {
printf("%02hhxH", (char) num);
}
cout<<endl;
}
return 0;
}
16位short型
Input an integer and it's type. such as
127 short
outout the two's complement of them.
007fH
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int num;
string st;
while(scanf("%lld",&num)!=-1){
cin>>st;
if (st=="short") {
printf("%04hxH",(short)num);
}
cout<<endl;
}
return 0;
}
32位int
Input an integer and it's type. such as
127 int
outout the two's complement of them.
0000007fH
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int num;
string st;
while(scanf("%lld",&num)!=-1){
cin>>st;
if(st=="int") {
printf("%08xH",(int)num);
}
cout<<endl;
}
return 0;
}
64位longlong
Input an integer and it's type. such as
127 longlong
outout the two's complement of them.
000000000000007fH
#include <bits/stdc++.h>
using namespace std;
int main() {
long long num;
string st;
while(scanf("%lld",&num)!=-1){
cin>>st;
if(st=="longlong") {
printf("%016llxH",num );
}
cout<<endl;
}
return 0;
}
十六进制转十进制
8位char和16位short十进制输出格式分别为%hhd,%hd
32位int和64位longlong十进制输出格式分别为%d,%lld
8位char型
Input an integer and it's type. such as
7f char
outout the two's complement of them.
127
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int num;
string cos;
while(scanf("%llx",&num)!=-1){
cin>>cos;
if(cos=="char") {
printf("%hhd", num);
}
cout<<endl;
}
return 0;
}
16位short型
Input an integer and it's type. such as
007f short
outout the two's complement of them.
127
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int num;
string cos;
while(scanf("%llx",&num)!=-1){
cin>>cos;
if (cos=="short") {
printf("%hd",num);
}
cout<<endl;
}
return 0;
}
32位int
Input an integer and it's type. such as
0000007f int
outout the two's complement of them.
127
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int num;
string cos;
while(scanf("%llx",&num)!=-1){
cin>>cos;
if(cos=="int") {
printf("%d",num);
}
cout<<endl;
}
return 0;
}
64位longlong
Input an integer and it's type. such as
000000000000007f longlong
outout the two's complement of them.
127
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int num;
string cos;
while(scanf("%llx",&num)!=-1){
cin>>cos;
if(cos=="longlong") {
printf("%lld",num );
}
cout<<endl;
}
return 0;
}