Java Number Swap swapBits(byte in)

Here you can find the source of swapBits(byte in)

Description

swap Bits

License

Open Source License

Declaration

public static byte swapBits(byte in) 

Method Source Code

//package com.java2s;
/*/* w w  w.j a  va2 s  .c o  m*/
  BinaryUtils.java
    
  (c) 2010-2012 Edward Swartz
    
  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 {
    static byte swapped_nybbles[] = { 0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe, 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7,
            0xf };

    public static byte swapBits(byte in) {
        return (byte) ((swapped_nybbles[in & 0xf] << 4) | (swapped_nybbles[(in & 0xf0) >> 4]));
    }
}

Related

  1. swap(T... args)
  2. swap16(final int aValue)
  3. swap16(short rgb)
  4. swap32(int rgb)
  5. swapAddresses(T o1, T o2)
  6. swapBits(int b, int i, int j)
  7. swapByte(byte b)
  8. swapBytes(final int i)
  9. swapCasing(String str)