code: def _required_byte_num(mode, fmt, n_samp):
      
  
      if fmt == '212':
          n_bytes = math.ceil(n_samp*1.5)
      elif fmt in ['310', '311']:
          n_extra = n_samp % 3
  
          if n_extra == 2:
              if fmt == '310':
                  n_bytes = upround(n_samp * 4/3, 4)
              # 311
              else:
                  if mode == 'read':
                      n_bytes = math.ceil(n_samp * 4/3)
                  # Have to write more bytes for wfdb c to work
                  else:
                      n_bytes = upround(n_samp * 4/3, 4)
          # 0 or 1
          else:
              n_bytes = math.ceil(n_samp * 4/3 )
      else:
          n_bytes = n_samp * BYTES_PER_SAMPLE[fmt]
  
      return int(n_bytes)
docs: Determine how many signal bytes are needed to read or write a
      number of desired samples from a dat file.
  
      Parameters
      ----------
      mode : str
          Whether the file is to be read or written: 'read' or 'write'.
      fmt : str
          The wfdb dat format.
      n_samp : int
          The number of samples wanted.
  
      Returns
      -------
      n_bytes : int
          The number of bytes required to read or write the file
  
      Notes
      -----
      Read and write require the same number in most cases. An exception
      is fmt 311 for n_extra==2.