Gets the higher 4 bits of a unsigned byte value. - Java java.lang

Java examples for java.lang:byte Array Bit Operation

Description

Gets the higher 4 bits of a unsigned byte value.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int b = 2;
        System.out.println(upperNibble(b));
    }//from  w  w  w  .j a v a2  s  . c o m

    /**
     * Gets the higher 4 bits of a unsigned byte value.
     *
     * @param b a unsigned byte (as int)
     * @return the value of the higher 4 bits
     */
    public static int upperNibble(int b) {
        // shift right 4 bits
        return b >> 4;
    }
}

Related Tutorials