Java Byte Create toByte(final int highNibble, final int lowNibble)

Here you can find the source of toByte(final int highNibble, final int lowNibble)

Description

Composes a byte from two nibbles.

License

Open Source License

Parameter

Parameter Description
highNibble the higher nibble
lowNibble the lower nibble

Return

a byte composed of the specified nibbles

Declaration

public static byte toByte(final int highNibble, final int lowNibble) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from w w  w.ja  v a 2 s.c om*/
     * Number of bits on a nibble.
     */
    public static final int BITS_SIZE_OF_NIBBLE = 4;
    /**
     * The mask for the low nibble of a byte.
     */
    public static final int INT_BYTE_LOW_NIBBLE_MASK = 0x0000000F;

    /**
     * Composes a byte from two nibbles.
     * 
     * @param highNibble the higher nibble
     * @param lowNibble the lower nibble
     * @return a byte composed of the specified nibbles
     */
    public static byte toByte(final int highNibble, final int lowNibble) {
        final int result = ((highNibble & INT_BYTE_LOW_NIBBLE_MASK) << BITS_SIZE_OF_NIBBLE)
                | (lowNibble & INT_BYTE_LOW_NIBBLE_MASK);

        return (byte) result;
    }
}

Related

  1. toByte(char c)
  2. toByte(char c)
  3. toByte(char hex)
  4. toByte(double x, double gamma)
  5. toByte(final byte[] buffer, final int offset)
  6. toByte(final String bitString)
  7. toByte(final String strHexa)
  8. toByte(final String value)
  9. toByte(float[][] in, byte[] out, float min, float max)