Here you can find the source of longToByteArray6(long addr)
Parameter | Description |
---|---|
addr | The long number. |
public static byte[] longToByteArray6(long addr)
//package com.java2s; /*// ww w . ja v a2 s .c o m * Copyright (c) 2013-2014 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 { /** * Constant holding the number of bits in a byte */ public static final int NumBitsInAByte = 8; /** * Constant holding the number of bytes in MAC Address */ public static final int MACAddrLengthInBytes = 6; /** * Converts a long number to a 6 bytes array for MAC addresses. * * @param addr The long number. * @return The byte array. */ public static byte[] longToByteArray6(long addr) { byte[] mac = new byte[MACAddrLengthInBytes]; int i = MACAddrLengthInBytes - 1; do { mac[i] = (byte) addr; addr >>>= NumBitsInAByte; i--; } while (i >= 0); return mac; } }