brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #494: Simplify BitUtils methods
Date Fri, 16 Dec 2016 16:22:16 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/494#discussion_r92839361
  
    --- 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 --
    
    Wow [`Integer.reverse`](https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/classes/java/lang/Integer.java#L1204)
does some interesting voodoo magic :).
    Should this be unsigned shift?



---
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.
---

Mime
View raw message