module BinData::Int

def create_clamp_code(nbits, signed)

def create_clamp_code(nbits, signed)
  if signed == :signed
    max = (1 << (nbits - 1)) - 1
    min = -(max + 1)
  else
    max = (1 << nbits) - 1
    min = 0
  end
  "val = (val < #{min}) ? #{min} : (val > #{max}) ? #{max} : val"
end