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!
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
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??
if anyone of you guys, didn't understand the above code, this my own code, which I made from a simpler logic.... #include #include 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
Here is another solution to this problem: #include #include 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); }
Here is the code for invalid input for eg:- 1201(which is not binary) #include int main() { //Initialization and user input int b,rem,decimal = 0,w = 1,num,c=0;//w = weight,b = binary printf("Enter binary number to covert to decimal "); scanf("%d",&b); num = b; //Binary to Decimal Conversion while(num!=0) { rem = num%10; if(rem>1) { printf("Invalid input:Input contains number other than 0 and 1 Please enter a valid input "); c = 1; break; } else { decimal = decimal + rem*w; num = num/10; w = w*2; } } //Printing result if(c==0) printf("%d is the decimal conversion of binary %d",decimal,b); }
Very good video. But I replicated the exact same code in Dart (doing the syntax changes) and the result was different! It gave me 11.24999999. There is my code in Dart: num binary = 1001; num decimal = 0; var base = 1; void main (){ while(binary != 0){ var rem = binary % 10; decimal = decimal + rem*base; binary = binary / 10; base = base*2; } print(decimal); } Can someone please explain to me where I'm wrong?
Hey I'm sorry you feel this way. This is actually fun if you get the concept, let me try and help. So the decimal number system (the system we naturally use) is very similar to the binary number system. Figuring out this key difference is all the logic you need to write the code. So for instance, to find the value of any decimal number we're actually multiplying each constituent digit with increasing powers of 10 for eg: 139 = 1*10^2 + 3*10^1 + 9*10^0 . It's just that we do this so naturally so that we don't usually give it a second thought. The decimal number system supports the digits [0-9] Comparing this with the very similar BINARY number system which just supports the digits 0 & 1, to get the value of a binary number we're simply multiplying the digit (bit) at each position with increasing powers of 2! for eg: 1011 represents 1 * 2^3 + 0 * 2^2 + 1 * 2^1 + 1 * 2^0 i.e the digit 11 in decimal. This is all the software engineering aspect there is. The rest is basically figuring out the fundamentals of any language to execute this. In fact, I would urge that you write your own code once you know this logic without referring the video. All you need to do that is i) knowledge of how to extract bit by bit from a given input ii) how to compute powers iii) how to use loops and conditional statements. Googling each of these gives you a clear idea of what they do. I hope i was able to help
I did this program using shift left operator(
Best channel for computer science students so far. Thanks for making such great contents.
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!
Idk how am I going to survive in IT field 😭
don't worry
@@ibtissamelhammoumy9586 thanks :-)
same here no logic only magic in programming
Don't worry bro me bhi apke jaisa hi sochta tha lekin dhire dhire Sab samaj ate jata hai bas koshish karte rho
It's 2024,how are u doing now bro
Sir this is so wonderful lecture
Thank you so much sir...today i understood the program and Sir please post binary to octal and hexadecimal too...
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
nice lecture I got a hint for the CodeChef challenge thanks
Thank you, sir. This really helped me with my paper 1 programming practice. From London
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
nice one
made the concept very clear
very helpful
best channel.................................................
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??
what?
have u read digital electronics???
if anyone of you guys, didn't understand the above code, this my own code, which I made from a simpler logic....
#include
#include
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
Sir u make more series on only focusing on problem..
Thank you I've learned a lot from you
Here is another solution to this problem:
#include
#include
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);
}
Absolutely Brilliant explanation
Very easy to understanding, thank you dear Sir.
#include
#include
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;
}
Thank you so much professor
It's amazing explanation ❤️
Very beautiful explanation sir.. u r amazing 🙏
u have explained it very well
awesomely explained
sir you are doing very great job
thank u for such a nice explaination!
All hail 🙌 Neso Academy
Wow 💜💜💜
... So nicely explained
very nice explanation thank you sir
You are Best.👏
Thank you so much 🙏🏽
Upload all videos in c language for learners
Sir please upload daily one video like circuit theory videos are being uploaded
Understood thankyou
thanks bro that was so helpful .
Thankyou so much sir
thanks sir
Outstanding
thankyou
I am getting error
Input :- 0011
Output :- 9
Expected output should : - 3
Please make videos on control systems.
Thank u
Sir pls cover the corners case also...
If I enter a binary contain more than 10 digit ....2. if I enter for eq-101101010101
Will your program work in these 2cases??
Here is the code for invalid input for eg:- 1201(which is not binary)
#include
int main()
{
//Initialization and user input
int b,rem,decimal = 0,w = 1,num,c=0;//w = weight,b = binary
printf("Enter binary number to covert to decimal
");
scanf("%d",&b);
num = b;
//Binary to Decimal Conversion
while(num!=0)
{
rem = num%10;
if(rem>1)
{
printf("Invalid input:Input contains number other than 0 and 1
Please enter a valid input
");
c = 1;
break;
}
else
{
decimal = decimal + rem*w;
num = num/10;
w = w*2;
}
}
//Printing result
if(c==0)
printf("%d is the decimal conversion of binary %d",decimal,b);
}
thanks bro for sharing
how to do it for decimal?
Super sir
Very helpful video sir
But you did not initialize rem in start. Will it not a problem to run this program?
Enta gamed strong
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 :(
As the weight of first digit from right side is zero then why we take it 1???
please give the flowchart and algorithm for this
Plzz make a vedio on how to convert decimal to binary plzz sir🙏🙏
#include
int main()
{
int var=65;
int i;
int bit;
for(i=8;i>0;i--)
{
bit=(var>>i-1) &1;
printf("%d",bit);
}
}
here you have,65 is the number converted to binary,the for its from 8 to 1,so you can store the bits from left to right
Sir u r going to upload videos in daily basis or not ???????
How to write it in a recursive function
what is weight??
It's a decimal value of number at certain position in a binary number.. Wn you travel from Lsb to msb... The value changes frm 2 to 2^n ..🙂
I just added a feature to this program, i.e., to display a error message when a non binary number is entered.
how r you pirate king??
What is the meaning of Weight here
Program for binary to hexa?
What about negative binary numbers🙄?
But what if the input is '101.011' or any other fractional binary number ? How to program that ?
Program dont work for 0011
Same bro
Bro agar hum koi or number add kare like as jo binary me na ho to code invalid ana chaiye to kaise hoga
In code blocks if I use space in print"%d " after %d before " once I build the code code block become stuck how I solve this
Sir I execute this program but the out put is not correct there is so different.what can I do
Binary to octal please bro..... >.
Why weight=1 and what r the purpose for use weight plz reply me
Weight is base
Initially base value will be 1 so we initialise weight with 1
@@arunjithajith7958 Thank u Arunjith
Is not working all values🤷♂🤷♂🤷♂🤷♂
Very good video. But I replicated the exact same code in Dart (doing the syntax changes) and the result was different! It gave me 11.24999999.
There is my code in Dart:
num binary = 1001;
num decimal = 0;
var base = 1;
void main (){
while(binary != 0){
var rem = binary % 10;
decimal = decimal + rem*base;
binary = binary / 10;
base = base*2;
}
print(decimal);
}
Can someone please explain to me where I'm wrong?
seems nothing wrong
if we give binary as 0000 ?
it's gonna return 0.
This code don't work in Python... Any help??
Problem solved: don`t worry any more folks
😢
How 1 divd by 10 remainder will b 1
10) 1 (0
0
-------------
1
I think this is the way
But not like
1) 10 (10
10*0=0..so remainder will be 1
First view, and first comment
Codes don't get executed which you teach in the window.....
Why did I choose software engineering? It's fucking hard
Hey I'm sorry you feel this way. This is actually fun if you get the concept, let me try and help.
So the decimal number system (the system we naturally use) is very similar to the binary number system. Figuring out this key difference is all the logic you need to write the code.
So for instance, to find the value of any decimal number we're actually multiplying each constituent digit with increasing powers of 10
for eg: 139 = 1*10^2 + 3*10^1 + 9*10^0 . It's just that we do this so naturally so that we don't usually give it a second thought. The decimal number system supports the digits [0-9]
Comparing this with the very similar BINARY number system which just supports the digits 0 & 1, to get the value of a binary number we're simply multiplying the digit (bit) at each position with increasing powers of 2!
for eg: 1011 represents 1 * 2^3 + 0 * 2^2 + 1 * 2^1 + 1 * 2^0 i.e the digit 11 in decimal.
This is all the software engineering aspect there is. The rest is basically figuring out the fundamentals of any language to execute this.
In fact, I would urge that you write your own code once you know this logic without referring the video. All you need to do that is
i) knowledge of how to extract bit by bit from a given input
ii) how to compute powers
iii) how to use loops and conditional statements.
Googling each of these gives you a clear idea of what they do.
I hope i was able to help
Don't worry yar. All will be good.. Better luck