bitfield.hh (4275:8a37341c7507) | bitfield.hh (4425:e94d396daad9) |
---|---|
1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 82 unchanged lines hidden (view full) --- 91/** 92 * Return val with bits first to last set to bit_val 93 */ 94template <class T, class B> 95inline 96T 97insertBits(T val, int first, int last, B bit_val) 98{ | 1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 82 unchanged lines hidden (view full) --- 91/** 92 * Return val with bits first to last set to bit_val 93 */ 94template <class T, class B> 95inline 96T 97insertBits(T val, int first, int last, B bit_val) 98{ |
99 T t_bit_val = bit_val; |
|
99 T bmask = mask(first - last + 1) << last; | 100 T bmask = mask(first - last + 1) << last; |
100 return ((bit_val << last) & bmask) | (val & ~bmask); | 101 return ((t_bit_val << last) & bmask) | (val & ~bmask); |
101} 102 103/** 104 * A convenience function to replace bits first to last of val with bit_val 105 * in place. 106 */ 107template <class T, class B> 108inline --- 294 unchanged lines hidden --- | 102} 103 104/** 105 * A convenience function to replace bits first to last of val with bit_val 106 * in place. 107 */ 108template <class T, class B> 109inline --- 294 unchanged lines hidden --- |