a) Chuyển đổi số hệ 10 sang hệ 2:
b) Chuyển đổi số hệ 2 sang hệ 10:
c) Chuyển đổi số hệ 10 sang hệ 16:
d) Chuyển đổi số hệ 10 sang hệ x (x<20):
e) Chuyển đổi số hệ 10 sang hệ 2 theo chuẩn IEEE754:
CODE:a)+c)+d)
- Code:
//10to2---(1)---(32767)
//10to3---(1)---(19682)
//10to4---(1)---(16383)
//10to5---(1)---(15624)
//10to6---(1)---(7775)
//10to7---(1)---(16806)
//10to8---(1)---(32767)
//10to9---(1)---(6560)
//10to10---(1)---(9999)
//10to11---(1)---(14640)
//10to12---(1)---(20735)
//10to13---(1)---(28560)
//10to14---(1)---(2743)
//10to15---(1)---(3374)
//10to16---(1)---(4095)
//10to17---(1)---(4912)
//10to18---(1)---(5831)
//10to19---(1)---(6858)
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int ex(int n)
{
if (n<10) return n+48;
else return n+55;
}
void solve(int n,int m)
{
int i=0;
char s[(int)(log(n)/log(m))+1];
do
{
s[i++]=ex(n%m);
n=n/m;
}
while (n!=0);
for (int j=i-1;j>=0;j--) printf("%c",s[j]);
}
int main()
{
int n=???;
int m=???;
printf("%d sang he %d la:\n",n,m);
solve(n,m);
getch();
return 0;
}
- Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
char *s="111111111111111";
int kq=0,len=strlen(s),i;
for (i=0;i<len;i++)
if (s[i]=='1') kq+=pow(2,len-i-1);
printf("%d",kq);
getch();
return 0;
}
- Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
char *chto2(unsigned char ch)
{
int temp=(int)ch;
char a[8];
int i=0;
for (i=0;i<8;i++) a[i]='0';
i=7;
do
{
a[i]=temp%2+48;
temp/=2;
i--;
}
while (temp!=0);
return a;
}
int main()
{
float f=-2048.123456789;
char *pByte=(char *)&f;
int i,j;
for (i=3;i>=0;i--)
{
unsigned char k=pByte[i];
for (j=0;j<8;j++) printf("%c",chto2(k)[j]);
printf(" ");
}
getch();
return 0;
}