diff --git a/Conversions/Binary To Decimal.c b/Conversions/Binary To Decimal.c deleted file mode 100644 index 93cb7d3f..00000000 --- a/Conversions/Binary To Decimal.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -int main() { - int number, decimal_number, temp=1; - printf("Enter any binary number= "); - scanf("%d", &number); - int remainder; - while(number>0) { - - remainder = number%10; - number = number/10; - decimal_number += remainder*temp; - temp = temp*2;//used as power of 2 - - } - printf("%d",decimal_number); -} diff --git a/conversions/decimal2Binary.c b/conversions/decimal2Binary.c new file mode 100644 index 00000000..8164fa5c --- /dev/null +++ b/conversions/decimal2Binary.c @@ -0,0 +1,38 @@ +/*********decimal number to binary number conversion*****************/ +#include +void decimal2Binary(long num); + +int main(){ + + long num; + + printf("Enter a decimal integer \n"); + scanf("%ld", &num); + decimal2Binary(num); + +return 0; +} + +/***function for convert decimal numbers to binary numbers****************/ +void decimal2Binary(long num){ + +long decimal_num, remainder, base, binary, no_of_1s; + +base = 1; +binary = 0; +no_of_1s = 0; + +while (num > 0) + { + remainder = num % 2; + + if (remainder == 1) + { + no_of_1s++; + } + binary = binary + remainder * base; + num = num / 2; + base = base * 10;} + + printf("Its binary equivalent is = %ld\n", binary); +} diff --git a/conversions/decimal2Hexa.c b/conversions/decimal2Hexa.c new file mode 100644 index 00000000..079b8183 --- /dev/null +++ b/conversions/decimal2Hexa.c @@ -0,0 +1,46 @@ +/*****Decimal to Hexadecimal conversion*******************/ +#include +void decimal2Hexadecimal(long num); + + +int main(){ + + long decimalnum; + + printf("Enter decimal number: "); + scanf("%ld", &decimalnum); + + decimal2Hexadecimal(decimalnum); + +return 0; +} + +/********function for convert decimal number to hexadecimal number****************/ +void decimal2Hexadecimal(long num){ + +long decimalnum=num; +long quotient, remainder; +int i, j = 0; +char hexadecimalnum[100]; + + quotient = decimalnum; + + while (quotient != 0){ + + remainder = quotient % 16; + if (remainder < 10) + hexadecimalnum[j++] = 48 + remainder; + + else + hexadecimalnum[j++] = 55 + remainder; + + quotient = quotient / 16;} + + // print the hexadecimal number + + for (i = j; i >= 0; i--){ + printf("%c", hexadecimalnum[i]);} + + printf("\n"); +} + diff --git a/conversions/decimal2Octal.c b/conversions/decimal2Octal.c new file mode 100644 index 00000000..2cc0d4c0 --- /dev/null +++ b/conversions/decimal2Octal.c @@ -0,0 +1,35 @@ +/*****Decimal to octal conversion*******************/ +#include +void decimal2Octal(long decimalnum); + +int main(){ + + long decimalnum; + + printf("Enter the decimal number: "); + scanf("%ld", &decimalnum); + + decimal2Octal(decimalnum); + +return 0; +} + +/********function for convert decimal numbers to octal numbers************/ +void decimal2Octal(long decimalnum){ + long remainder, quotient; + + int octalNumber[100], i = 1, j; + quotient = decimalnum; + + while (quotient != 0){ + octalNumber[i++] = quotient % 8; + + quotient = quotient / 8; + } + + for (j = i - 1; j > 0; j--) + + printf("%d", octalNumber[j]); + + printf("\n"); +}