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 D7A4F200BF7 for ; Mon, 9 Jan 2017 11:57:06 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D63A5160B3E; Mon, 9 Jan 2017 10:57:06 +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 50CE1160B3B for ; Mon, 9 Jan 2017 11:57:06 +0100 (CET) Received: (qmail 28076 invoked by uid 500); 9 Jan 2017 10:57:05 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 28065 invoked by uid 99); 9 Jan 2017 10:57:05 -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; Mon, 09 Jan 2017 10:57:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2FC9DDFB6E; Mon, 9 Jan 2017 10:57:05 +0000 (UTC) From: grkvlt To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #494: Simplify BitUtils methods Content-Type: text/plain Message-Id: <20170109105705.2FC9DDFB6E@git1-us-west.apache.org> Date: Mon, 9 Jan 2017 10:57:05 +0000 (UTC) archived-at: Mon, 09 Jan 2017 10:57:07 -0000 Github user grkvlt commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/494#discussion_r95134861 --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/math/BitUtils.java --- @@ -18,25 +18,22 @@ */ package org.apache.brooklyn.util.math; +import com.google.common.primitives.Bytes; +import com.google.common.primitives.Ints; + public class BitUtils { /** reverses the bits in a byte, i.e. 128 = 0b1000000 = bit list {0,0,0,0,0,0,0,1}, * reversed yields 1 = 0b00000001 = bit list {1,0,0,0,0,0,0,0} */ public static byte reverseBitSignificance(byte b) { - int result = 0; - for (int i=0; i<8; i++) { - result <<= 1; - if ((b&1)==1) result++; - b >>= 1; - } - return (byte)result; + return (byte) (Integer.reverse(b) >> 24); --- End diff -- No. The following tests should convince you: ``` Assert.assertEquals(BitUtils.reverseBitSignificanceInByte(0b00000001), (byte)0b10000000); Assert.assertEquals(BitUtils.reverseBitSignificanceInByte(0x0f), (byte)0xf0); ``` --- 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. ---