Here you can find the source of intToShortArray(final int intValue)
Parameter | Description |
---|---|
intValue | int value. |
public static short[] intToShortArray(final int intValue)
//package com.java2s; /*//from ww w.j ava 2 s . co m * Copyright 2013, Carsten J?ger * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Constant 4. */ public static final byte CONST_4 = 4; /** * Constant 8. */ public static final byte CONST_8 = 8; /** * Constant 255. */ public static final short CONST_255 = 255; /** * Converts an int value to a 4-byte length short array. * * @param intValue int value. * @return short array. */ public static short[] intToShortArray(final int intValue) { final short[] result = new short[CONST_4]; for (byte i = CONST_4 - 1; i >= 0; --i) { result[i] |= ((intValue >>> CONST_8 * ((CONST_4 - 1) - i)) & (CONST_255)); } return result; } }