Morton Numbers
InterviewTime limit2sMemory limit512 MB
Read integers x and y and print their Morton number, built by interleaving the bits of x and y.
- Level
Easy1 of 10
- Topics
- Bit manipulation
- Solved
- No attempts yet
Problem
The Morton number of two integers and is the integer built by interleaving the bits of and the bits of one place at a time. The bits of go to the even numbered places and the bits of go to the odd numbered places, where places are counted upward from the least significant bit, which is the first place.
Write for the -th bit of and for the -th bit of , so that and the same holds for . The Morton number is then
If and are read as the coordinates of a point in the plane, two points that lie close together have Morton numbers that lie close together as well. The Morton number also grows when or grows.
Given and in base 10, write a program that prints their Morton number in base 10.
Input
The first line contains the integers and separated by whitespace. ()
Output
Print the Morton number of and on the first line.