集册 Java实例教程 将指定的短字符串转换为字节数组。

将指定的短字符串转换为字节数组。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

438
将指定的短字符串转换为字节数组。

/*

 * Licensed to the Apache Software Foundation (ASF) under one or more

 * contributor license agreements.  See the NOTICE file distributed with

 * this work for additional information regarding copyright ownership.

 * The ASF licenses this file to You 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.

 */
 /*
 时 代      J a v a   公   众 号 - nowjava.com 提供
 */

//package com.nowjava;


public class Main {

    /**

     * Convert the specified short into a byte array.

     *

     * @param value

     *            The value to be converted.

     * @param array

     *            The array to receive the data.

     * @param offset

     *            The offset into the byte array for the start of the value.

     */

    public static void shortToByteArray(final short value,

            final byte[] array, final int offset) {

        array[offset] = (byte) (value >>> 8);

        array[offset + 1] = (byte) value;

    }


    /**

     * Convert the specified short into a byte array.

     *

     * @param value

     *            The value to be converted.

     * @return The byte array

     */

    public static byte[] shortT
展开阅读全文