# Path: pyphysim/util/misc.py
# def xor(a: int, b: int) -> int:
#     """
#     Calculates the xor operation between a and b.
# 
#     In python this is performed with a^b. However, sage changed the "^"
#     operator. This xor function was created so that it can be used in
#     either sage or in regular python.
# 
#     Parameters
#     ----------
#     a : int
#         First number.
#     b : int
#         Second number.
# 
#     Returns
#     -------
#     int
#         The result of the `xor` operation between `a` and `b`.
# 
#     Examples
#     --------
#     >>> xor(3,7)
#     4
#     >>> xor(15,6)
#     9
#     """
#     return a.__xor__(b)


from typing import Optional, TypeVar
from .misc import xor
import numpy as np
    Examples
    --------
    >>> linear2dBm(1000)
    60.0
    """
    return linear2dB(valueInLinear * 1000.)


# Code from wikipedia
# http://en.wikipedia.org/wiki/Gray_code#Constructing_an_n-bit_Gray_code
def binary2gray(num: IntOrIntArray) -> IntOrIntArray:
    """
    Convert a number (in decimal format) to the corresponding Gray code
    (still in decimal format).

    Parameters
    ----------
    num : int | np.ndarray
        The number in decimal encoding

    Returns
    -------
    num_gray : int | np.ndarray
        Corresponding gray code (in decimal format) of `num`.

    Examples
    --------
    >>> binary2gray(np.arange(0, 8))
    array([0, 1, 3, 2, 6, 7, 5, 4])
    """

# Path: pyphysim/util/misc.py
# def xor(a: int, b: int) -> int:
#     """
#     Calculates the xor operation between a and b.
# 
#     In python this is performed with a^b. However, sage changed the "^"
#     operator. This xor function was created so that it can be used in
#     either sage or in regular python.
# 
#     Parameters
#     ----------
#     a : int
#         First number.
#     b : int
#         Second number.
# 
#     Returns
#     -------
#     int
#         The result of the `xor` operation between `a` and `b`.
# 
#     Examples
#     --------
#     >>> xor(3,7)
#     4
#     >>> xor(15,6)
#     9
#     """
#     return a.__xor__(b)


# Path: pyphysim/util/conversion.py
from typing import Optional, TypeVar
from .misc import xor
import numpy as np

    Examples
    --------
    >>> linear2dBm(1000)
    60.0
    """
    return linear2dB(valueInLinear * 1000.)


# Code from wikipedia
# http://en.wikipedia.org/wiki/Gray_code#Constructing_an_n-bit_Gray_code
def binary2gray(num: IntOrIntArray) -> IntOrIntArray:
    """
    Convert a number (in decimal format) to the corresponding Gray code
    (still in decimal format).

    Parameters
    ----------
    num : int | np.ndarray
        The number in decimal encoding

    Returns
    -------
    num_gray : int | np.ndarray
        Corresponding gray code (in decimal format) of `num`.

    Examples
    --------
    >>> binary2gray(np.arange(0, 8))
    array([0, 1, 3, 2, 6, 7, 5, 4])
    """

    return xor((num >> 1), num)