Java Long to String long2string(long lng, StringBuilder buff)

Here you can find the source of long2string(long lng, StringBuilder buff)

Description

longstring

License

Open Source License

Declaration

private static void long2string(long lng, StringBuilder buff) 

Method Source Code

//package com.java2s;
/*-/* w w  w .j  a v  a 2  s.  c  om*/
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

public class Main {
    private static final char[] CHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
            'C', 'D', 'E', 'F' };

    private static void long2string(long lng, StringBuilder buff) {
        for (int i = 0; i < 16; i++) {
            long nextByte = lng & 0xF000000000000000L;
            lng <<= 4;
            boolean isNegative = nextByte < 0;
            nextByte = rightShift(nextByte, 60);

            if (isNegative) {
                nextByte |= 0x08;
            }

            buff.append(CHARS[(int) nextByte]);
        }
    }

    private static long rightShift(long lng, int num) {
        return lng >>> num;
    }
}

Related

  1. long2sortableStr(long val)
  2. Long2Str(long i)
  3. long2String(final long ip)
  4. Long2String(final long value)
  5. long2string(long longdata)
  6. long2String(long x)
  7. long2StringForLen(long num, String str)
  8. long2Word(long val)