All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.swiftboot.util.BitUtils Maven / Gradle / Ivy

The newest version!
package org.swiftboot.util;

import java.util.Collection;

/**
 * @author swiftech
 **/
public class BitUtils {

    /**
     * 判断一个数字的二进制位是否和另外一个数字的二进制位重叠
     *
     * @param target
     * @param body
     * @param 
     * @return
     */
    public static  boolean contains(T target, T body) {
        return (target.longValue() & body.longValue()) > 0;
    }

    /**
     * 对集合中的所有长整数做逻辑或操作,相当于合并所有二进制位
     *
     * @param longs
     * @return 返回操作结果
     */
    public static long bitwiseOr(Collection longs) {
        long result = 0;
        if (longs == null)
            return result;
        for (Long lon : longs) {
            if (lon != null) {
                result = result | lon;
            }
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy