Created
October 6, 2018 04:55
-
-
Save Vivek-abstract/f10e697040fee67175856cad8b133bc4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
print("Enter number of elements: ") | |
n = int(input()) | |
elements, binary_elements = [], [] | |
for i in range(n): | |
# Take input and store in array | |
x = int(input()) | |
elements.append(x) | |
# Convert to binary array of 8 bits | |
binary_elements.append('{0:08b}'.format(x)) | |
sum = '00000000' | |
print("Number\tGray Level\tSum\t\tIGS Code") | |
for i in range(n): | |
if binary_elements[i][:4] == '1111': | |
# Add 0000 => don't add anything | |
sum = binary_elements[i] | |
else: | |
# Add 4 bits of LSB of sum to input | |
sum = '{0:08b}'.format(int(sum[4:],2) + elements[i]) | |
print("%d\t%s\t%s\t%s" % (elements[i], binary_elements[i], sum, sum[:4])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: