{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Generic Primitive Examples" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from byteclasses.print import byteclass_info, byteclass_inspect\n", "from byteclasses.types.primitives.generics import Bit, Byte, DWord, QWord, Word" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "generic_types = [Byte, Word, DWord, QWord]\n", "for i, generic_type in enumerate(generic_types):\n", " var = generic_type(b\"\\xFF\" * 2**i)\n", " byteclass_info(var)\n", " byteclass_inspect(var)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bit = Bit(True) # Bit is a convenience class and is not considered a byteclass" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "try:\n", " byteclass_info(bit)\n", "except TypeError as err:\n", " print(err)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "try:\n", " byteclass_inspect(bit)\n", "except TypeError as err:\n", " print(err)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(bit)\n", "print(bit.value)\n", "# Bit has no data attribute" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 2 }