Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 68F79200CAE for ; Wed, 21 Jun 2017 14:23:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 675EB160BE2; Wed, 21 Jun 2017 12:23:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D4785160BD0 for ; Wed, 21 Jun 2017 14:23:13 +0200 (CEST) Received: (qmail 12812 invoked by uid 500); 21 Jun 2017 12:23:13 -0000 Mailing-List: contact issues-help@carbondata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@carbondata.apache.org Delivered-To: mailing list issues@carbondata.apache.org Received: (qmail 12803 invoked by uid 99); 21 Jun 2017 12:23:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Jun 2017 12:23:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DBD76DFBA2; Wed, 21 Jun 2017 12:23:12 +0000 (UTC) From: jackylk To: issues@carbondata.apache.org Reply-To: issues@carbondata.apache.org References: In-Reply-To: Subject: [GitHub] carbondata pull request #1065: [CARBONDATA-1196] Add 3 bytes data type suppo... Content-Type: text/plain Message-Id: <20170621122312.DBD76DFBA2@git1-us-west.apache.org> Date: Wed, 21 Jun 2017 12:23:12 +0000 (UTC) archived-at: Wed, 21 Jun 2017 12:23:14 -0000 Github user jackylk commented on a diff in the pull request: https://github.com/apache/carbondata/pull/1065#discussion_r123231835 --- Diff: core/src/main/java/org/apache/carbondata/core/util/ByteUtil.java --- @@ -465,6 +465,39 @@ public static short toShort(byte[] bytes, int offset, final int length) { } /** + * int => byte[3] + * supported range is [-8388607, 8388607], note that Math.pow(2, 24) == 8388608 + */ + public static byte[] to3Bytes(int val) { + assert val <= (Math.pow(2, 23) - 1) && val >= (-Math.pow(2, 23) + 1); + + int value = val < 0 ? -val : val; + byte[] b = new byte[3]; + b[0] = (byte) (value & 0xFF); + b[1] = (byte) ((value >>> 8) & 0xFF); + b[2] = (byte) ((value >>> 16) & 0x7F); + if (val < 0) { + b[2] |= 0x80; + } + return b; + } + + /** + * convert 3 bytes to int + */ + public static int valueOf3Bytes(byte[] val, int offset) { + assert val.length >= offset + 3; + int out = (val[offset] & 0xFF); + out |= ((val[offset + 1] & 0xFF) << 8); + out |= ((val[offset + 2] & 0x7F) << 16); + if ((val[offset + 2] & 0x80) != 0) { + return -out; + } else { + return out; + } --- End diff -- ok --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---