Java Binary Encode toBinArray(String hexStr)

Here you can find the source of toBinArray(String hexStr)

Description

to Bin Array

License

Open Source License

Declaration

public static byte[] toBinArray(String hexStr) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static byte[] toBinArray(String hexStr) {
        byte bArray[] = new byte[hexStr.length() / 2];
        for (int i = 0; i < (hexStr.length() / 2); i++) {
            byte firstNibble = Byte.parseByte(hexStr.substring(2 * i, 2 * i + 1), 16); // [x,y)
            byte secondNibble = Byte.parseByte(hexStr.substring(2 * i + 1, 2 * i + 2), 16);
            int finalByte = (secondNibble) | (firstNibble << 4); // bit-operations only with numbers, not bytes.
            bArray[i] = (byte) finalByte;
        }//w  w  w .  j a  v a2  s.co m
        return bArray;
    }
}

Related

  1. toBin(byte n)
  2. toBin(int bin, int size)
  3. toBin(int size, String bitString)
  4. toBin(int x)
  5. toBin(long value, int width)
  6. toBinary(byte b)
  7. toBinary(byte b)
  8. toBinary(byte b)
  9. toBinary(byte b)