diff --git a/src/V3Number.h b/src/V3Number.h index 5541c33e6..cf2700185 100644 --- a/src/V3Number.h +++ b/src/V3Number.h @@ -56,10 +56,19 @@ public: V3Number& setDouble(double value); void setBit (int bit, char value) { // Note must be pre-zeroed! if (bit>=m_width) return; - if (value=='0'||value==0) m_value [bit/32] &= ~(1UL<<(bit&31)); - else { - if (value=='1'||value=='x'||value==1||value==3) m_value [bit/32] |= (1UL<<(bit&31)); - if (value=='z'||value=='x'||value==2||value==3) m_valueX[bit/32] |= (1UL<<(bit&31)); + uint32_t mask = (1UL<<(bit&31)); + if (value=='0' || value==0) { + m_value [bit/32] &= ~mask; + m_valueX[bit/32] &= ~mask; + } else if (value=='1'|| value==1) { + m_value [bit/32] |= mask; + m_valueX[bit/32] &= ~mask; + } else if (value=='z'|| value==3) { + m_value [bit/32] &= ~mask; + m_valueX[bit/32] |= mask; + } else { // X + m_value [bit/32] |= mask; + m_valueX[bit/32] |= mask; } } private: