/
NikolayIvkin
/
TheAlgorithms
Обзор
Документация
Войти
/
NikolayIvkin
/
TheAlgorithms
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/com/thealgorithms/bitmanipulation/BitSwap.java
15 строк
443 B
Lukas
Bit swap (#4770)
15 окт 2023, 10:03
Не верифицирован
15 окт 2023, 10:03
48ae88f
Код
Авторство
О чём код?
package com.thealgorithms.bitmanipulation; public final class BitSwap { private BitSwap() { } /* * @brief Swaps the bits at the position posA and posB from data */ public static int bitSwap(int data, final int posA, final int posB) { if (SingleBitOperations.getBit(data, posA) != SingleBitOperations.getBit(data, posB)) { data ^= (1 << posA) ^ (1 << posB); } return data; } }