s=b[0]|b[1];
t=b[0]^b[1];
The ASCII value of 0 is 48 and that of 1 is 49. Here 0 and 1 are decimal numbers and not binary. There is no direct way of treating a number as binary in C, you have to do it manually.As far I know there is no ASCII value for 1 or 0. So what will be the ASCII value that will be stored in the string? Please help me because I cannot find a way out to operate with the bits.
#include <stdio.h>
int main()
{
char b[100];
int s, t, x, y;
scanf("%[^\t\n]s",b); /*scanf to accept multi-word string*/
if(b[0]=='0')
x=0;
else
x=1;
if(b[1]=='0')
y=0;
else
y=1;
s=x|y;t=x^y;
printf("%c \n%c",s,t);return 0;
}
#include <stdio.h>
int main()
{
char b[100],s,t;
scanf("%[^\t\n]s",b); /*scanf to accept multi-word string*/
for(int temp=0; temp<100; ++temp)
b[temp]-='0';
s=b[0]|b[1];
t=b[0]^b[1];
printf("%c \n%c",s,t);
return 0;
}
#include <stdio.h>
int main()
{
char b[100],s,t;
scanf("%[^\t\n]s",b); /*scanf to accept multi-word string*/
for(int i=0; b[i]!=NULL; ++i)
b[i]-='0';
for(int i=0; ++i<digits.size()-1; ++i)
{
--i;
s=digits[i]|digits[i+1];
t=digits[i]&digits[i+1];
printf("\nOR: %d", s);
printf("\nAND: %d", t);
printf("/n");
}
printf("%c \n%c",s,t);return 0;}
Dude, dont be dumb, at least mention what is the problem occurring. And even if it's not working, the logit of treating the string as binary digits is clearly mentioned in the code. use your brain to correct the code and understand the logic. We are here to suggest and to point the wrong, not to do what's your's work.Its not working.