code: def binarize(
      tensor: tf.Tensor,
      bitsize: Optional[int] = None,
  ) -> tf.Tensor:
      """Extract bits of values in `tensor`, returning a `tf.Tensor` with same
      dtype."""
  
      with tf.name_scope("binarize"):
          bitsize = bitsize or (tensor.dtype.size * 8)
  
          bit_indices_shape = [1] * len(tensor.shape) + [bitsize]
          bit_indices = tf.range(bitsize, dtype=tensor.dtype)
          bit_indices = tf.reshape(bit_indices, bit_indices_shape)
  
          val = tf.expand_dims(tensor, -1)
          val = tf.bitwise.bitwise_and(
              tf.bitwise.right_shift(val, bit_indices), 1
          )
  
          assert val.dtype == tensor.dtype
          return val
  
file_path: tf-encrypted/tf_encrypted/tensor/shared.py
imports: import math
  from typing import Optional
  import tensorflow
label_desc: Use image node_id 1 for calling a global function with example usage: binarize(tensor, bitsize) and returns: val