#include <stdio.h>
#include <math.h>
int main()
{
printf("Enter 3 binaries to convert them to decimals \n");
for(int i = 0 ; i < 3 ; i++)
{
long long bin = 0, dec = 0;
scanf("%lld", &bin);
long long trash = bin , amount = 0;
while(trash>=1)
{
trash = trash / 10; ///calculatinng the length of the number
amount++;
}
for(int i = 0 ; i < amount ; i++)
{
int num = 0;
num = bin % 10;
bin = bin / 10; ///converting in line power method
dec = dec + pow(2 , i) * num;
}
printf("%lld \n", dec);
}
printf("Enter 3 decimals to convert them to binaries \n");
for(int i = 0 ; i < 3; i++)
{
long long dec = 0 , bin = 0;
scanf("%lld", &dec);
int lvl = 0;
while(dec > 0)
{
bin = bin + dec % 2 * pow(10, lvl); ///converting in column method
dec = dec / 2;
lvl++;
}
printf("%lld \n", bin);
}
printf("Enter 3 heximals to convert them into decimals \n");
for(int i = 0 ; i < 3 ; i++)
{
long long num = 0;
scanf("%x", &num); ///using C language advantages to convert the number
printf("%d \n", num);
}
printf("Enter 3 decimals to convert them into heximals \n");
for(int i = 0 ; i < 3 ; i++)
{
long long num = 0;
scanf("%d", &num); ///using C language advantages to convert the number
printf("%x \n", num);
}
return 0;
}
Replies to Untitled
Title |
Name |
Language |
UNIX |
When |
Re: Untitled |
Eratic Cheetah |
text |
1631972113 |
2 Years ago. |
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}