Converts a 16-bits into a 2x2 matrix f nibbles column wise. - Java java.lang

Java examples for java.lang:Math Convert

Description

Converts a 16-bits into a 2x2 matrix f nibbles column wise.

Demo Code

/** Copyright 2014 Noel Niles
 * /* w w w .  ja v  a  2 s  .  c om*/
 * This file is part of SAES.
 *
 * S-AES is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
//package com.java2s;

public class Main {
    /** Converts a 16-bits into a 2x2 matrix f nibbles column wise.
     * 
     * @param s A short that needs to be a matrix.
     * @return 2x2 matrix of nibbles.
     **************************************************************************/
    protected static byte[][] shortToMatrix(final short s) {
        byte[][] m = new byte[2][2];
        m[0][0] = (byte) ((s >>> 12) & 0xf);
        m[1][0] = (byte) ((s >>> 8) & 0xf);
        m[0][1] = (byte) ((s >>> 4) & 0xf);
        m[1][1] = (byte) (s & 0xf);
        return m;
    }
}

Related Tutorials