/* Copyright (C) 2018 David Robillard Copyright (C) 2006-2007 Chris Hamilton This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef CHILBERT_SETBITS_HPP #define CHILBERT_SETBITS_HPP #include "chilbert/Operations.hpp" namespace chilbert { /** Set a range of bits in one field from the start of another. * * @param h Destination bit field * @param n Number of bits * @param i Start bit index in destination * @param w Source bit field */ template inline void setBits(H& h, const size_t n, const size_t i, const I& w) { for (size_t j = 0; j < n; j++) { setBit(h, i + j, testBit(w, j)); } } } // namespace chilbert #endif