Special Programs in C − Binary to Decimal Conversion

preview_player
Показать описание
C Programming & Data Structures: C Program For Binary to Decimal Conversion.
Topics discussed:
1) Binary to decimal conversion.
2) C program to convert binary number to its decimal equivalent.

Music:
Axol x Alex Skrindo - You [NCS Release]

#CProgrammingByNeso #CProgramming #BinaryToDecimalProgram
Рекомендации по теме
Комментарии
Автор

Here is another solution to this problem:

#include <stdio.h>

#include <math.h>

int main()
{
long long int number, num, result, n;

printf("Please Enter the Binary number: ");
scanf("%lld", &number);
result = 0;
n =0;
num = number;
while(num != 0)
{
result = result + (num % 10) * pow(2, n) ;
n++;
num = num / 10;
}
printf("%lld in decimal is %lld", number, result);
return (0);
}

itsbayahmed
Автор

Idk how am I going to survive in IT field 😭

-HarishkumarG
Автор

Best channel for computer science students so far. Thanks for making such great contents.

sunnygomes
Автор

I did this program using shift left operator(<<), you can change the line ( decimal = decimal + rem*weight ;) with ( decimal= decimal + rem<<weight ;) and remove (weight = weight *2 ; ) and initialize weight with zero and it'll give you the same output, cuz shifting left is equal to multiplying with 2^weight

boblopez
Автор

Thank you so much
Sir one day I will be in the good position definitely on that day I will sponsor huge amount money to our channel

madhavikatta
Автор

Thank you so much sir...today i understood the program and Sir please post binary to octal and hexadecimal too...

mayankjadhav
Автор

Great lecture. Many ways this can be done (including using the math.h library and utilizing the pow() function) but the previous person that taught me this didn't explain why we were doing the modulus and division in a clear way. You, however, did. Thanks!

Obama
Автор

nice one
made the concept very clear
very helpful

roshnimishra
Автор

if anyone of you guys, didn't understand the above code, this my own code, which I made from a simpler logic....

#include <stdio.h>
#include <math.h>
int main(void) {
// example : convert 1 0 0 1 to decimal
// [1]*2^(3)+ [0]*2^(2)+ [0]*2^(1) + [1]*2^(0)
printf("enter a binary number : ");
int n;
scanf("%d", &n);
int temp = n;
int rem = 0;
int result = 0;
int count = 0;
int last_num= 0;
while (temp!=0) {
temp = temp/10;
count++;
}
temp = n;
for (int i = 0; i<count; i++) {
rem = temp%10;
last_num = rem * pow(2, i);
result = result+last_num;
temp = temp/10;
}
printf("%d is the required decimal number.", result);
return 0;
}

if you have any doubts go ahead and ask!

aakashmudigonda
Автор

We store hex value starts with 0x, and octal starts with 0 and decimal as it is in the integer type..
How do we store a binary number in the integer type??
Here why do we convert a decimal number to decimal again??
Where actually is it useful??
Can someone please explain??

ashokkumark
Автор

nice lecture I got a hint for the CodeChef challenge thanks

nikhilsingh
Автор

#include <stdio.h>
#include <math.h>

int main ( void ) {

int binary;

printf ( "Enter binary number: " );
scanf ( "%d", &binary );

int counter1 = 0;
int A = binary;

while ( A != 0 ) {
A /= 10;
counter1++;
}

int remainder = 0;
int power = 0;
int sum = 0;
for ( int counter2 = 0; counter2 < counter1; counter2++ ) {
remainder = binary % 10;
power = ( pow ( ( remainder * 2 ), counter2 ) ) * remainder ;
sum += power;
binary /= 10;
}
printf ( "Decimal Equivalent = %d", sum );

return 0;
}

zoreladreanrivera
Автор

Sir u make more series on only focusing on problem..

Deepthi_Chowdary
Автор

i did it using biwise operators! it worked! ig
int bin_dec()
{
int bin, dec;
scanf("%d", &bin);
for (int shift; bin!=0; shift++)
{
int r = bin%10;
dec = (r<<shift)|dec;
bin /= 10;
}
printf("%d", dec);

}

dambro
Автор

Thank you, sir. This really helped me with my paper 1 programming practice. From London

rudrachakraborty
Автор

if i want to check if the number have only 1 and 0 how can i do that?
if it has other number, send error message :(

Khadra
Автор

Thank you I've learned a lot from you

arnoldgatchalian
Автор

Upload all videos in c language for learners

tumutarun
Автор

Very beautiful explanation sir.. u r amazing 🙏

YashDEVELOPER
Автор

Very easy to understanding, thank you dear Sir.

HuynhThanhThuan
visit shbcf.ru