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

Java examples for java.lang:byte Array Bit Operation

Description

Gets the lower 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(lowerNibble(b));
    }//w  ww  .  j  a  v a2 s. co  m

    /**
     * Gets the lower 4 bits of a unsigned byte value.
     *
     * @param b a unsigned byte (as int)
     * @return the value of the lower 4 bits
     */
    public static int lowerNibble(int b) {
        return b & 0x0000000F;
    }
}

Related Tutorials