Last active
January 31, 2021 10:49
-
-
Save vishalsingha/e17637b908066c107503b4b4cce38dc0 to your computer and use it in GitHub Desktop.
BIT wise.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "BIT wise.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyN5ghG1dkr275k8J63ElKKh", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/vishalsingha/e17637b908066c107503b4b4cce38dc0/untitled13.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "2Ql9w4YvBLdu", | |
"outputId": "0f35e86a-eb7d-4c81-9e93-926dcce039db" | |
}, | |
"source": [ | |
"a = 12 #binary form of a = 1010\r\n", | |
"b = 10 #binary form of b = 1100\r\n", | |
"\r\n", | |
"print(a|b) # Bitwise OR on 1010 and 1100 is 1110, which in binary representation of 14.\r\n", | |
"\r\n", | |
"print(a&b) # Bitwise AND on 1010 and 1100 is 1010, which is binary representation of 10." | |
], | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"14\n", | |
"8\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "9rZFdTyhDXke" | |
}, | |
"source": [ | |
"XOR returns 0 when both operands are 1's or both are 0's else it returns 1." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "E4l9XCUTBw6y", | |
"outputId": "91aee330-8d25-416d-a245-ee0800007144" | |
}, | |
"source": [ | |
"print(a^b) # # Bitwise XOR on 1010 and 1100 is 0110, which is binary representation of 6." | |
], | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"6\n" | |
], | |
"name": "stdout" | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment