Set the value, potentially converting an unsigned
        value to a signed one (and visa versa)
501753
def _pfp__set_value(self, new_val):
        """"""
        if self._pfp__frozen:
            raise errors.UnmodifiableConst()

        if isinstance(new_val, IntBase):
            # will automatically convert correctly between ints of
            # different sizes, unsigned/signed, etc
            raw = new_val._pfp__build()
            while len(raw) < self.width:
                if self.endian == BIG_ENDIAN:
                    raw = b"\x00" + raw
                else:
                    raw += b"\x00"

            while len(raw) > self.width:
                if self.endian == BIG_ENDIAN:
                    raw = raw[1:]
                else:
                    raw = raw[:-1]

            self._pfp__parse(six.BytesIO(raw))
        else:
            mask = 1 << (8*self.width)

            if self.signed:
                max_val = (mask//2)-1
                min_val = -(mask//2)
            else:
                max_val = mask-1
                min_val = 0
            
            if new_val < min_val:
                new_val += -(min_val)
                new_val &= (mask-1)
                new_val -= -(min_val)
            elif new_val > max_val:
                new_val &= (mask-1)

            self._pfp__value = new_val

        self._pfp__notify_parent()
813648
def convert_representation(self, i):
        
        if self.number_representation == 'unsigned':
            return i
        elif self.number_representation == 'signed':
            if i & (1 << self.interpreter._bit_width - 1):
                return -((~i + 1) & (2**self.interpreter._bit_width - 1))
            else:
                return i
        elif self.number_representation == 'hex':
            return hex(i)
1073924
def _set_as_int(self, addr, val, numBytes = 1):
        """"""
        if not isinstance(val, int):
            raise ValueError("val must be an int. You provided: %s" % str(val))
        buf = []
        for i in range(numBytes):
            buf.append(cast_to_byte(val >> 8 * i))
        self.set_register(addr, buf)
384770
def uint32(self, val):
        """"""
        try:
            self.msg += [pack("!I", val)]
        except struct.error:
            raise ValueError("Expected uint32")
        return self
1318627
def encode(cls, value):
        
        try:
            coerced = bytes(value)
            if coerced == value:
                return coerced
        except (TypeError, UnicodeError):
            pass

        raise InvalidValue('not binary')
377979
def _SignedVarintSize(value):
  """"""
  if value < 0: return 10
  if value <= 0x7f: return 1
  if value <= 0x3fff: return 2
  if value <= 0x1fffff: return 3
  if value <= 0xfffffff: return 4
  if value <= 0x7ffffffff: return 5
  if value <= 0x3ffffffffff: return 6
  if value <= 0x1ffffffffffff: return 7
  if value <= 0xffffffffffffff: return 8
  if value <= 0x7fffffffffffffff: return 9
  return 10
1013253
def append_var_uint64(self, unsigned_value):
        
        if not 0 <= unsigned_value <= wire_format.UINT64_MAX:
            raise errors.EncodeError('Value out of range: %d' % unsigned_value)
        while True:
            bits = unsigned_value & 0x7f
            unsigned_value >>= 7
            if unsigned_value:
                bits |= 0x80
            self._buffer.append(bits)
            if not unsigned_value:
                break
691129
def _bit_value(self, group, val):
        """"""
        bitshift = group - 1
        if val:
            new_value = self._value | (1 << bitshift)
        else:
            new_value = self._value & (0xff & ~(1 << bitshift))
        return new_value
33014
def _send_byte(self,value):
        

        # Coerce to int. This will throw a ValueError if the value can't
        # actually be converted.
        if type(value) != int:
            new_value = int(value)

            if self.give_warnings:
                w = "Coercing {} into int ({})".format(value,new_value)
                warnings.warn(w,Warning)
                value = new_value

        # Range check
        if value > 255 or value < 0:
            err = "Value {} exceeds the size of the board's byte.".format(value)
            raise OverflowError(err)

        return struct.pack("B",value)
971706
def WriteUInt160(self, value):
        
        if type(value) is UInt160:
            value.Serialize(self)
        else:
            raise Exception("value must be UInt160 instance ")
669001
def _setuie(self, i):
        
        if i < 0:
            raise CreationError("Cannot use negative initialiser for unsigned "
                                "interleaved exponential-Golomb.")
        self._setbin_unsafe('1' if i == 0 else '0' + '0'.join(bin(i + 1)[3:]) + '1')
1306593
def unsigned_integer(self, column, auto_increment=False):
        
        return self.integer(column, auto_increment, True)
524085
def WriteUInt256(self, value):
        
        if type(value) is UInt256:
            value.Serialize(self)
        else:
            raise Exception("Cannot write value that is not UInt256")
1026939
def u32(self, name, value=None, align=None):
        """"""
        self.uint(4, name, value, align)
1369512
def write_uint32(self, value, little_endian=True):
        
        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.pack('%sI' % endian, value)
333922
def _SignedVarintEncoder():
  """"""

  local_chr = chr
  def EncodeSignedVarint(write, value):
    if value < 0:
      value += (1 << 64)
    bits = value & 0x7f
    value >>= 7
    while value:
      write(0x80|bits)
      bits = value & 0x7f
      value >>= 7
    return write(bits)

  return EncodeSignedVarint
552905
def int_subtype(i, bits, signed) :
        ""
        if not isinstance(i, int) :
            raise TypeError("value is not int: %s" % repr(i))
        #end if
        if signed :
            lo = - 1 << bits - 1
            hi = (1 << bits - 1) - 1
        else :
            lo = 0
            hi = (1 << bits) - 1
        #end if
        if i < lo or i > hi :
            raise ValueError \
              (
                "%d not in range of %s %d-bit value" % (i, ("unsigned", "signed")[signed], bits)
              )
        #end if
        return \
            i