@@ -0,0 +1,1781 @@
+/**%0A * Copyright %C2%A9 2014  Mattias Andr%C3%A9e (maandree@member.fsf.org)%0A * %0A * This program is free software: you can redistribute it and/or modify%0A * it under the terms of the GNU Affero General Public License as published by%0A * the Free Software Foundation, either version 3 of the License, or%0A * (at your option) any later version.%0A * %0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU Affero General Public License for more details.%0A * %0A * You should have received a copy of the GNU Affero General Public License%0A * along with this program.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A */%0Apackage algorithms.bits;%0A%0A%0A/**%0A * Operations on individual bits%0A */%0Apublic class Bits%0A%7B%0A%C2%A3%3Efor T in char byte short int long; do%0A    /**%0A     * Sets or clears individual bits in an integer%0A     * %0A     * @param   value  The value to modify%0A     * @param   mask   Mask of bits to modify%0A     * @param   flag   1 if the bit should be set, 0 if the bit should be clears%0A     * @return         The value with the bits modified%0A     */%0A    public static %C2%A3%7BT%7D set_clear(%C2%A3%7BT%7D value, %C2%A3%7BT%7D mask, %C2%A3%7BT%7D flag)%0A    %7B%0A%09return (%C2%A3%7BT%7D)(value %5E ((-flag %5E value) & mask));%0A    %7D%0A    %0A    /**%0A     * Sets or clears individual bits in an integer, superscalar version%0A     * %0A     * @param   value  The value to modify%0A     * @param   mask   Mask of bits to modify%0A     * @param   flag   1 if the bit should be set, 0 if the bit should be clears%0A     * @return         The value with the bits modified%0A     */%0A    public static %C2%A3%7BT%7D set_clear_superscalar(%C2%A3%7BT%7D value, %C2%A3%7BT%7D mask, %C2%A3%7BT%7D flag)%0A    %7B%0A%09return (%C2%A3%7BT%7D)((value & ~mask) %7C (-flag & mask));%0A    %7D%0A%C2%A3%3Edone%0A%7D%0A%0A

add set_clear