+ 6
Can someone help me fix this code?
My problem is: How to get the result from the conversion Supposedly the result will be checked in if((n&(n>>1))==0) https://code.sololearn.com/cz5m85QG5aJw/?ref=app
34 Antworten
+ 11
Yes by checking like this.
while(num > 0) {
i = num % 10;
if((i != 0) || (i != 1) {
//Not binary number
break;
}
j = num / 10;
if(j == 0) {
//Binary Number
break;
}
}
+ 9
Check here what I did. You have to return entered number not i Because you are checking Fibbinary Number on entered number.
So I stored entered number in another variable n so we can return the exact entered value. We also can't return number because it's decreasing each time in loop so finally it will be 0 which we don't want.
https://code.sololearn.com/cJYblftwbeBK/?ref=app
+ 8
Alby check your code int n,i,result you didn't used result it's giving error correct your program.
+ 8
Alby first understand number system conversion clear your concepts.
+ 8
Alby Take one number convert it manually
+ 8
Mike Abo Don't use such words keep this thread clean.Only ask proper questions in this thread.
+ 7
Alby check the code which 🅰🅹 - ɪ'ᴍ ᴄʀɪᴍɪɴᴀʟʟʏ ɢᴏᴏᴅ! sent and ask your question properly don't get confused.
+ 7
Show me that example then I will understand what's your exact problem right
+ 6
Alby I already shown the code above. There we are doing both things checking Fibbinary Number as well as converting in Decimal Number.
If we can check Fibbinary Number directly then why you are thinking to check converted binary number
+ 6
Alby You got binary number in that code. Now you can check consecutive of 1 in that binary number if you found then it's not Fibbinary Number. Try to get it self.
+ 6
Jack In this thread only ask proper questions don't chat here keep this thread clean.
+ 5
Alby What do you want actually? You want Fibbinary Number or Check Binary Number or converted binary to decimal number.
I think you are confused.
+ 5
Alby 101 is Fibbinary Number. Check my code, run it and enter 5 then you will get.
+ 5
Alby Input is 5, Binary Number of this input is 101 and 5 or 101 is Fibbinary Number. Why you are so confused bro.
+ 5
Alby Go through this link and try to understand.
http://www.c4learn.com/c-programming/c-bitwise-right-shift/
+ 5
https://code.sololearn.com/cBnm3R056RoX/?ref=app
Here's the code if you only need to check for Fibbinary Number <very short>
+ 4
Thanks
+ 4
Alby Check again and you still didn't update your code?
+ 4
🅰🅹 - ɪ'ᴍ ᴄʀɪᴍɪɴᴀʟʟʏ ɢᴏᴏᴅ! Updated already A Big Thank You
+ 3
After the conversion is there any way that the code checks the Converted [binary numbers] if it is a Fibbinary or not, rather than the Decimal?
Help thanks..
If this will work
Where im going to put
Code i = num % 10
....
....
Where am i gonna put this?
Is it going to replace if((n&(n>>1))==0)
Or
Is it going to replace conversion function [process]