Java ASCII from toASCIICode(byte[] bts)

Here you can find the source of toASCIICode(byte[] bts)

Description

to ASCII Code

License

Open Source License

Declaration

public static byte[] toASCIICode(byte[] bts) 

Method Source Code

//package com.java2s;

public class Main {
    public static byte[] toASCIICode(byte[] bts) {
        byte[] format_str = new byte[128];
        int btsLength = bts.length;
        int year = btsLength > 1 ? bts[0] * 256 + 256 + bts[1] : 1900;
        int month = btsLength > 2 ? bts[2] : 1;
        int day = btsLength > 3 ? bts[3] : 1;
        int hour = btsLength > 4 ? bts[4] : 0;
        int minute = btsLength > 5 ? bts[5] : 0;
        int second = btsLength > 6 ? bts[6] : 0;

        int index = 3;
        int temp = year;
        for (; index >= 0; index--) {
            format_str[index] = (byte) (48 + (temp - temp / 10 * 10));
            temp /= 10;/*  w ww .j  a  v a  2 s. c o m*/
        }
        format_str[4] = '-';
        index = 6;
        temp = month;
        for (; index >= 5; index--) {
            format_str[index] = (byte) (48 + (temp - temp / 10 * 10));
            temp /= 10;
        }
        format_str[7] = '-';
        index = 9;
        temp = day;
        for (; index >= 8; index--) {
            format_str[index] = (byte) (48 + (temp - temp / 10 * 10));
            temp /= 10;
        }
        format_str[10] = ',';
        index = 12;
        temp = hour;
        for (; index >= 11; index--) {
            format_str[index] = (byte) (48 + (temp - temp / 10 * 10));
            temp /= 10;
        }
        format_str[13] = ':';
        index = 15;
        temp = minute;
        for (; index >= 14; index--) {
            format_str[index] = (byte) (48 + (temp - temp / 10 * 10));
            temp /= 10;
        }
        format_str[16] = ':';
        index = 18;
        temp = second;
        for (; index >= 17; index--) {
            format_str[index] = (byte) (48 + (temp - temp / 10 * 10));
            temp /= 10;
        }
        return format_str;
    }
}

Related

  1. toAsciiByteArray(String s)
  2. toAsciiBytes(final String value)
  3. toAsciiBytes(String str)
  4. toAsciiChar(byte b)
  5. toAsciiChar(int i)
  6. toAsciiFilename(String string)
  7. toAsciiLowerCase(char ch)
  8. toAsciiString(byte[] buffer)
  9. toAsciiString(byte[] buffer, int startPos, int length)