QNLP  v1.0
gray.py
Go to the documentation of this file.
1 import ctypes
2 from .encoder_base import EncoderBase
3 
5  """
6  Adapated from example on https://en.wikipedia.org/wiki/Gray_code
7  """
8  def encode(self, bin_val : ctypes.c_uint):
9  return bin_val ^ ( bin_val >> 1)
10 
11  def decode(self, bin_val : ctypes.c_uint):
12  bitmask = bin_val >> 1
13  val = bin_val
14  while bitmask != 0:
15  val = val ^ bitmask
16  bitmask = bitmask >> 1
17  return val
def encode(self, ctypes.c_uint bin_val)
Definition: gray.py:8
def decode(self, ctypes.c_uint bin_val)
Definition: gray.py:11