could someone tell me why it didn't give me 1 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

could someone tell me why it didn't give me 1

#include <stdio.h> int main(){ int x = 43; int y = 65; int result = x & y; printf("%d",result); return 0; }

17th Oct 2023, 7:32 PM
Amin
Amin - avatar
11 Answers
+ 7
128 64 32 16 8 4 2 1 0 0 1 0 1 0 1 1 = 43 0 1 0 0 0 0 0 1 = 65 - - - - - - - - - - - - 0 0 0 0 0 0 0 1 = 1
17th Oct 2023, 8:38 PM
Jan
Jan - avatar
+ 4
Amin, which do you believe is correct, ChatGPT's answer, or yours? Before you decide, be sure to read the disclaimer on ChatGPT's opening page. 😉
17th Oct 2023, 8:05 PM
Brian
Brian - avatar
+ 2
BroFar true=1/false=0 is useful if in context of logical &&, but bitwise & may evaluate to other values. In this case the result happens to be 1, because bit0 is the only bit that is in common between 43 and 65.
18th Oct 2023, 1:43 AM
Brian
Brian - avatar
+ 1
Amin what did you get? It prints 1 for me, as it should.
17th Oct 2023, 7:48 PM
Brian
Brian - avatar
+ 1
Sorry buddy It give me 1 too. But Chat GPT tell me that it must be 65 ( a decimal )
17th Oct 2023, 7:52 PM
Amin
Amin - avatar
+ 1
It gives 1. xD
17th Oct 2023, 7:56 PM
Werg Serium
Werg Serium - avatar
+ 1
In c language Zero is used to represent false, and One is used to represent true.
18th Oct 2023, 12:40 AM
BroFar
BroFar - avatar
+ 1
Robert please do not spam the question and answer forum. Wrecklessly doing so may get your account suspended or terminated.
19th Oct 2023, 12:17 AM
BroFar
BroFar - avatar
+ 1
Это использование побитового метода в языке C. Kotali KaN
19th Oct 2023, 8:10 PM
BroFar
BroFar - avatar
0
Brian this is an example of what I was referencing to in my earlier statement using bitwise in c language. https://code.sololearn.com/cJoeUTdpn46R/?ref=app
19th Oct 2023, 12:19 AM
BroFar
BroFar - avatar
0
Что этов се такое?😂
19th Oct 2023, 7:21 PM
Kotali KaN
Kotali KaN - avatar