Java Long to Byte Array longToByteArray6(long addr)

Here you can find the source of longToByteArray6(long addr)

Description

Converts a long to 6 bytes array for mac addresses

License

Open Source License

Parameter

Parameter Description
addr a parameter

Declaration


public static byte[] longToByteArray6(long addr) 

Method Source Code

//package com.java2s;
/*//from   ww  w .  ja va 2  s  . c  o  m
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

public class Main {
    /**
     * Converts a long to 6 bytes array for mac addresses
     * @param addr
     * @return
     */

    public static byte[] longToByteArray6(long addr) {
        byte[] mac = new byte[6];
        for (int i = 0; i < 6; i++) {
            mac[i] = (byte) (addr >> (i * 8));
        }
        return mac;
    }
}

Related

  1. longToByteArray(long value, byte[] buffer, int offset)
  2. longToByteArray(long value, byte[] byteArray)
  3. longToByteArray(long value, byte[] data, int offset)
  4. longToByteArray(long value, byte[] dest)
  5. longToByteArray(long value, int nrOfBytes)
  6. longToByteArray6(long addr)
  7. longToByteArrayBE(long data)
  8. longToByteArrayForAS(long i)
  9. longToByteBounds(long value)