Value Conversions#

Convert to Booleans#

Important

Boolean literals are strings and not values!

You can convert each signal sample to bool by calling the method bool().

A new Trace instance labeled with the performed transformation 'bool' is returned.

>>> Trace('Signal', [-1, 0, 1]).bool()
Trace(label='Signal:bool', samples=[True, False, True])
>>> Trace('Signal', [-1, 0, 1]).bool().int()
Trace(label='Signal:bool:int', samples=[1, 0, 1])

(Source code, html)

Convert to Integers#

You can convert each signal sample to int by calling the method int().

A new Trace instance labeled with the performed transformation 'int' is returned.

>>> Trace('Signal', [-0.5, 0.0, 0.5]).int()
Trace(label='Signal:int', samples=[0, 0, 0])
>>> Trace('Signal', [-0.5, 0.0, 0.5]).int().float()
Trace(label='Signal:int:float', samples=[0.0, 0.0, 0.0])

(Source code, html)

Convert to Floats#

You can convert the signal samples to float by calling the method float().

A new Trace instance labeled with the performed transformation 'float' is returned.

>>> Trace('Signal', [-1, 0, 1]).float()
Trace(label='Signal:float', samples=[-1.0, 0.0, 1.0])
>>> Trace('Signal', [-1, 0, 1]).float().int()
Trace(label='Signal:float:int', samples=[-1, 0, 1])

(Source code, html)

Convert to Binary#

Important

Binary number literals are strings and not values!

You can convert each signal sample to binary literals by calling the method bin().

A new Trace instance labeled with the performed transformation 'bin' is returned.

>>> Trace('Signal', [-1, 0, 1]).bin()
Trace(label='Signal:bin', samples=['-0b1', '0b0', '0b1'])
>>> Trace('Signal', [-1, 0, 1]).bin().int(0)
Trace(label='Signal:bin:int', samples=[-1, 0, 1])
>>> Trace('Signal', [-1, 0, 1]).bin().int(2)
Trace(label='Signal:bin:int', samples=[-1, 0, 1])

(Source code, html)

Convert to Octal#

Important

Octal number literals are strings and not values!

You can convert each signal sample to octal literals by calling the method oct().

A new Trace instance labeled with the performed transformation 'oct' is returned.

>>> Trace('Signal', [-1, 0, 1]).oct()
Trace(label='Signal:oct', samples=['-0o1', '0o0', '0o1'])
>>> Trace('Signal', [-1, 0, 1]).oct().int(0)
Trace(label='Signal:oct:int', samples=[-1, 0, 1])
>>> Trace('Signal', [-1, 0, 1]).oct().int(8)
Trace(label='Signal:oct:int', samples=[-1, 0, 1])

(Source code, html)

Convert to Hexadecimal#

Important

Hexadecimal literals are strings and not values!

You can convert each signal sample to hexadecimal literals by calling the method hex().

A new Trace instance labeled with the performed transformation 'hex' is returned.

>>> Trace('Signal', [-1, 0, 1]).hex()
Trace(label='Signal:hex', samples=['-0x1', '0x0', '0x1'])
>>> Trace('Signal', [-1, 0, 1]).hex().int(0)
Trace(label='Signal:hex:int', samples=[-1, 0, 1])
>>> Trace('Signal', [-1, 0, 1]).hex().int(16)
Trace(label='Signal:hex:int', samples=[-1, 0, 1])

(Source code, html)