
Author: Gihyun Kim
Date: March 16th, 2024
Topic: Bitwise Operators & Uses
What are Bitwise Operators?
Bitwise operators are operators that are able to perform different tasks with the individual components of binary numbers.
Here are some examples:
bitwise AND: &
– Returns 1 if both bits of the binary numbers are 1 but returns 0 otherwise
bitwise OR: |
– Returns 1 if a bit of any of the two operands are 1 but returns 0 otherwise
bitwise exclusive OR (XOR): ^
– Returns 1 if the bits of two operands are different but returns 0 otherwise
bitwise NOT: ~
– Flips all the bits of the operand
ex) ~1000 ==> 0111
Left shift: <<
– Shifts the bits of the operand to the left by a certain number of positions
Right shift: >>
– Shifts the bits of the operand to the right by a certain number of positions
Uses:
The following practice question provided by will show how the bitwise operators can be used.
Practice question:
The people of Lilliput were divided into two groups, the Big Endian faction, which argued that boiled eggs should be broken starting from the wide end, and the Little Endian faction, which argued that the eggs should be broken starting from the narrow end. This fight has expanded to boiled eggs and other areas of life, a representative example of which is the method of storing data used in computers.
The Big-Endian side argued that when storing numbers, it is correct to store the upper byte first. The Little-Endian side argued that storing the lower byte first was correct.
For example, if 32bit unsigned int 305,419,896 is expressed in Big Endian and Little Endian, it is as follows:
[Little Endian]
high address low address
00010010 00110100 01010110 01111000
[Big Endian]
high address low address
01111000 01010110 00110100 00010010
Each of these people created and used computers in their own way, and when people from two factions needed to exchange data with each other (they didn’t always fight). If data stored in Big Endian is read as is in Little Endian, or vice versa, it will result in strange values, so Endian conversion is necessary.
For example, if the Big Endian value in the example above is read as Little Endian, it becomes 2,018,915,346 (0x78563412).
Since they did not want to convert the Endian themselves and send the data, once they received the data, they had to convert it to fit the Endian they used.
You must help them by writing a program that restores the received data to its original data without converting Endian.
Input
The input consists of a single number (32bit unsigned int), which is data accepted without Endian conversion.
Print
Outputs the original data for the input.
Solution:
The solution was created by me and was checked to be correct.


Question source:
https://www.jungol.co.kr/problem/1419/submission?cursor=eyJwcm9ibGVtc2V0IjoiMTAiLCJmaWVsZCI6MCwiaWR4IjoyfQ%3D%3D

Leave a comment