0% found this document useful (0 votes)
7 views

bitwise-operators-in-c-hackerrank

This document explains bitwise operators in C, including AND, OR, and XOR, with examples using integers. It presents a challenge to find the maximum values of specific bitwise operations that are less than a given integer from a set of integers. The input format consists of space-separated integers, and the output includes the maximum possible values for each operation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

bitwise-operators-in-c-hackerrank

This document explains bitwise operators in C, including AND, OR, and XOR, with examples using integers. It presents a challenge to find the maximum values of specific bitwise operations that are less than a given integer from a set of integers. The input format consists of space-separated integers, and the output includes the maximum possible values for each operation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Bitwise Operators

Objective
This challenge will let you learn about bitwise operators in C.

Inside the CPU, mathematical operations like addition, subtraction, multiplication and division are done in
bit-level. To perform bit-level operations in C programming, bitwise operators are used which are
explained below.

Bitwise AND operator & The output of bitwise AND is 1 if the corresponding bits of two operands is 1.
If either bit of an operand is 0, the result of corresponding bit is evaluated to 0. It is denoted by &.

Bitwise OR operator | The output of bitwise OR is 1 if at least one corresponding bit of two operands
is 1. It is denoted by |.

Bitwise XOR (exclusive OR) operator ^ The result of bitwise XOR operator is 1 if the corresponding
bits of two operands are opposite. It is denoted by .

For example, for integers 3 and 5,

3 = 00000011 (In Binary)


5 = 00000101 (In Binary)

AND operation OR operation XOR operation


00000011 00000011 00000011
& 00000101 | 00000101 ^ 00000101
________ ________ ________
00000001 = 1 00000111 = 7 00000110 = 6

Task
Given set , find:

the maximum value of which is less than a given integer , where and (where ) are two
integers from set .

the maximum value of which is less than a given integer , where and (where ) are two
integers from set .

the maximum value of which is less than a given integer , where and (where ) are
two integers from set .

Input Format

The only line contains space-separated integers, and , respectively.

Constraints

Output Format

The first line of output contains the maximum possible value of .

The second line of output contains the maximum possible value of .

The second line of output contains the maximum possible value of .

Sample Input 0
54

Sample Output 0

2
3
3

Explanation 0

All possible values of and are:

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

The maximum possible value of that is also is , so we print on first line.

The maximum possible value of that is also is , so we print on second line.

The maximum possible value of that is also is , so we print on third line.

You might also like