Android String to Byte Array Convert StrToBcdBytes(String s)

Here you can find the source of StrToBcdBytes(String s)

Description

Str To Bcd Bytes

Parameter

Parameter Description
s a parameter

Declaration

public static byte[] StrToBcdBytes(String s) 

Method Source Code

//package com.java2s;
import java.io.ByteArrayOutputStream;

public class Main {
    /**//ww w  .  ja v a 2  s . c  o  m
     *
     * @param s
     * @return
     */
    public static byte[] StrToBcdBytes(String s) {
        if (s.length() % 2 != 0) {
            s = "0" + s;
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        char[] c = s.toCharArray();
        for (int i = 0; i < c.length; i += 2) {
            int high = c[i] - 48;
            int low = c[i + 1] - 48;
            baos.write(high << 4 | low);
        }

        return baos.toByteArray();
    }
}

Related

  1. getBytes(String data, String charsetName)
  2. getBytesFromAddress(String address)
  3. stringToBytes(String string)
  4. String2Byte(String hexString)
  5. StringToByteArray(String input)
  6. Str2Bcd(String asc)
  7. toBytes(String digits, int radix)
  8. toBytes(String hexString)
  9. toBytes(String hexString)