/* 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_GETBITS_HPP #define CHILBERT_GETBITS_HPP #include "chilbert/Operations.hpp" namespace chilbert { /** Copy a range of bits from one field to the start of another. * * @param h Source bit field * @param n Number of bits * @param i Start bit index in source * @param w Destination bit field */ template inline void getBits(const H& h, const size_t n, const size_t i, I& w) { for (size_t j = 0; j < n; j++) { setBit(w, j, testBit(h, i + j)); } } } // namespace chilbert #endif