I'd like to use decimal numbers one by one, but I don't know at all.
Please let me know if you understand.
15&7
6 & 4
9 OR 3
5 OR 10
I thought that the 9OR3
in question was looking for a decimal representation of 9|3
.
※ The bit operation for OR in C language is |
and the bit operation for AND is &
.
The idea is to convert numbers to binary numbers, perform &(AND) and |(OR) bit operations one bit at a time, and then convert the results to decimal numbers.
If you just want to know the answer, you can use printf to display the bit results as follows:
printf("%d\n", 15&7);
[Added]
The operator of the logical operation in C language is &&
and the OR is |
.
The C language can treat integers as true or false values.
The true or false value of integer 0 is false, and any integer other than 0 is true.When evaluating, 1 or 2 is true, but the result is 1.
If any of the two integers is 0 (false), the logical AND (&
) result is 0 (false), and if both integers are non-zero, the result is 1 (true).
If both integers are 0 (false), the logical OR (||
) result is 0 (false), and the result is true (1) when at least one integer is non-zero.
Bit operations can be considered as logical operations for each bit.
"The question said ""I want to express it in decimal"", so I thought it was a bit operation and answered it without permission, but
"
I added it to my answer because I thought it would be better to understand the difference between logical operation and bit operation.
© 2024 OneMinuteCode. All rights reserved.