Java Long to String long2sortableStr(long val)

Here you can find the source of long2sortableStr(long val)

Description

longsortable Str

License

Apache License

Declaration

public static String long2sortableStr(long val) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String long2sortableStr(long val) {
        char[] arr = new char[5];
        long2sortableStr(val, arr, 0);
        return new String(arr, 0, 5);
    }//from  ww w . j  av  a 2  s  .c  om

    public static String long2sortableStr(String val) {
        return long2sortableStr(Long.parseLong(val));
    }

    public static int long2sortableStr(long val, char[] out, int offset) {
        val += Long.MIN_VALUE;
        out[offset++] = (char) (val >>> 60);
        out[offset++] = (char) (val >>> 45 & 0x7fff);
        out[offset++] = (char) (val >>> 30 & 0x7fff);
        out[offset++] = (char) (val >>> 15 & 0x7fff);
        out[offset] = (char) (val & 0x7fff);
        return 5;
    }
}

Related

  1. Long2Str(long i)
  2. long2String(final long ip)
  3. Long2String(final long value)
  4. long2string(long lng, StringBuilder buff)