Gets the high byte of an integer. - Java java.lang

Java examples for java.lang:byte Array to int

Description

Gets the high byte of an integer.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int b = 2;
        System.out.println(highByte(b));
    }//w w  w  . j av  a 2  s . com

    /**
     * Gets the high byte of an integer.
     *
     * @param b the int value
     * @return the right shifted (8-bits) byte value
     */
    public static byte highByte(int b) {
        return (byte) (b >> 8 & 0x000000FF);
    }
}

Related Tutorials