Friday, March 14, 2014

Reversed Binary Numbers (Difficulty Level: Easy)

My friend sent me a quiz how to make a reverse binary from input number and put it back as number.
It is easy level though, I had fun of it
If you are interested to get more quiz, please check this https://code.google.com/codejam/
There are many programing quiz in Internet. I see there are so many genius in the world.
I wonder when I can resolve the difficult level of quiz. I must study math again.


Task

Your task will be to write a program for reversing numbers in binary. For instance, the binary representation of 13 is 1101, and reversing it gives 1011, which corresponds to number 11.

Input

The input contains a single line with an integer N, 1 ≤ N ≤ 1000000000.

Output

Output one line with one integer, the number we get by reversing the binary representation of N.

Sample input 1
13
Sample output 1
11
Sample input 2
47
Sample output 2
61




package puzzle;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author jack
 */
public class Reversebinary {

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String input;

            while ((input = br.readLine()) != null) {
                int inputValue = Integer.parseInt(input);

//                System.out.println(Integer.toBinaryString(inputValue));

                StringBuffer revertedString = new StringBuffer();
                revertedString.append(Integer.toBinaryString(inputValue)).reverse();

//                System.out.println(revertedString);
                System.out.println(Long.parseLong(revertedString.toString(), 2));

            }

        } catch (java.lang.NumberFormatException ne) {
            System.out.println("Please type numbers");
        } catch (IOException io) {
            io.printStackTrace();

        }
    }
}

How to get the apk out of the non-rooted Android device

I got a request to test updated Android application. but, it often happens that I need to test without apk file.
Due to complicated commpany rules, politics and security, the requester can't send me the apk file.. But, they push me to do..
To resolve this situation, luckily I had one Android device which is installed the latest apk. but, I need to test it on another device.
I can extract the apk from an Anroid device and install it on the other devices.

To do this step, Android SDK is required. so that you will be able use 'adb' command.

Step to extract apk file from an Android device.
1. Connect the device to the computer
2. start command prompt or shell
3. adb shell pm list package -f -3 (to display all the installed apps on the device)
C:\>adb shell pm list package -f -3
package:/data/app/autotechniksteeg.preistafel-1.apk=autotechniksteeg.preistafel
...
package:/data/app/uk.amazon.mShop.android-2.apk=uk.amazon.mShop.android
...

4. adb pull {apk name} (This will save the required apk on the current directory of the computer)
C:\>adb pull /data/app/uk.amazon.mShop.android-2.apk


If you remove '-3' option, it will show all apk which is pre-loaded app on your device. I used 'adb shell pm list package -f -3' command.
If you like to know more about 'pm list package' filter option, please refer below.
pm list packages: prints all packages, optionally only
  those whose package name contains the text in FILTER.  Options:
    -f: see their associated file.
    -d: filter to only show disbled packages.
    -e: filter to only show enabled packages.
    -s: filter to only show system packages.
    -3: filter to only show third party packages.
    -i: see the installer for the packages.
    -u: also include uninstalled packages.