[C / C ] Show us some 2, Contacts 8, Contacts 16 of decimal
To display of system 10 to other systems, usually we think of how we change the algorithm with other systems. If you want so you can find on Google has many articles about the algorithm then, here he set a certain way that we do not need to use algorithms that can display immediately.
CEO: Enter 1 Some systems 10 then output system 16.
#include <stdio.h> #include <stdlib.h> void Hex(int n) { if (n < 16) { printf("%c","0123456789ABCDEF"[n]); // hien thi ky tu thu n trong chuoi return; } else Hex(n / 16); printf("%c","0123456789ABCDEF"[n % 16]); } int main() { int n; printf("Enter your number: "); scanf("%d", &n); printf("Number in hex:"); Hex(n); return 0; }
If you look closely, in the code above we use the algorithm still divided 16 Using recursive. This applies also good for us 2 and Us 8. Also we can use the function to convert ltoa (the search yourself).
So do not use algorithms then how? Simple as follows:
#include <stdio.h> #include <stdlib.h> int main() { int n; printf("Enter your number: "); scanf("%d", &n); printf("Number in hex: %X", n); // in ra so Hex bang dinh dang %X return 0; }
Simple and concise not? :D.
More information:
To perform some kind of something as a certain number of systems: for example, you enter a whole number now want to perform it on the screen.
– Generation format 10 use% d
– Generation format 8 use% o
– Generation format 16 use% x (or X to uppercase letters)
Notice, we can enter the number system 16 or system 8 and print out the system 8, 10, 16 you want.
VD into the system 16 print out of system 8, Contacts 10.
#include <stdio.h> #include <stdlib.h> int main() { int n; printf("Enter your number in Hex: "); scanf("%x", &n); printf("Number in Oct: %on", n); printf("Number in Dec: %dn", n); return 0; }
KQ:
Enter your number in Hex: D2F
Number in Oct: 6457
Number in Dec: 3375
Refer to:
The difference between% d and% i in C programming
Print out the hex
convert a decimal number to Contacts 16 or system 2, fastest way
Waiter. if you want to move through the space binary “%…” what sir?
Generation 2 they must use only algorithms, I also do not know how it performed off.
void decToBin(int n)
{
if(n <= 1)
{
printf("% D", n);
}
else
{
decToBin(n/2);
printf("% D", n%2);
}
}
#include <stdio.h>
void decToBin(int n)
{
if(n < 10)
{
printf("% D", n);
}
else if(n < 16)
{
switch(n)
{
case 10: printf("A"); break;
case 11: printf("B"); break;
case 12: printf("C"); break;
case 13: printf("D"); break;
case 14: printf("E"); break;
case 15: printf("F"); break;
}
}
else
{
decToBin(n/16);
printf("% D", n);
}
}
main()
{
// decToBin(30);
for(int i = 9; in <= 40; i )
{
printf("\n%d = ", in);
decToBin(in);
}
}
This code is wrong darling in pieces anyway
This you need to change the system 10. sau đó đổi từ hệ 10 về hệ 2.
không phải anh ơi em đang chuyển từ hệ 10 sang 16 cơ mà
Thế mà ghi decToBin(10 sang 2)
Sửa lại code như sau nhé:
Em cảm ơn 😀
sai thứ tự else
{
decToBin(n/16);
printf(“%d”, n);
}
thế mà nghĩ mãi không ra 😀
anh ơi cho em hỏi chuyển từ hệ 16 to Us 10 ta viết như thế nào dùng C++
Bạn ơi cho mình hỏi mình muốn biểu diễn số phức trong hệ hexa phải làm sao vậy?
Mình cũng chưa tìm hiểu cái này 🙂
KQ want to print reverse system 16 then how Bro
Thanks for your useful article. But I still have not understood and little wonder: if you want to transfer the results to display the ASCII code (dev c ++ in) from generation 10 to the other systems we have to how? I thank!
In all that you have all gone.
no way to change his fast. I mean so :))
I want to convert from binary to hexa then ntn sir’
You can turn over 10 and then hex.