{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "ec5412d2", "metadata": {}, "outputs": [], "source": [ "import numpy as np \n" ] }, { "cell_type": "code", "execution_count": 2, "id": "be1f0d01", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0, 1])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "byte1= np.array([0x12, 0xe3, 0x9b])\n", "byte2 = np.array([0x12, 0xe3, 0x9c])\n", "b1 = np.array([0,0])\n", "b2 = np.array([0,1])\n", "b1\n", "b2" ] }, { "cell_type": "code", "execution_count": 6, "id": "c256a3d0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0 0 7]\n" ] }, { "data": { "text/plain": [ "array([0, 1], dtype=uint8)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v = byte1^byte2\n", "v1 = np.array (v,dtype = np.uint8)\n", "print(v1)\n", "v2 = b1^b2\n", "v2 = np.array (v2,dtype = np.uint8)\n", "v2" ] }, { "cell_type": "code", "execution_count": 7, "id": "227f0142", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1]\n" ] }, { "data": { "text/plain": [ "array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], dtype=uint8)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z = np.unpackbits(v1)\n", "print(z)\n", "z1 = np.unpackbits(v2)\n", "z1" ] }, { "cell_type": "code", "execution_count": 5, "id": "092d8dae", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = sum(z)\n", "a" ] }, { "cell_type": "code", "execution_count": null, "id": "0ac2e304", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "034142b6", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "f203fbce", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.2" } }, "nbformat": 4, "nbformat_minor": 5 }