RE: Bit flipping
April 23, 2016 at 10:40 pm
(This post was last modified: April 23, 2016 at 10:40 pm by SteelCurtain.)
Just so you can get an idea of what I'm doing:
The code above is converting the gray code to a binary code.
Prompt Wrote:The Computer Science Central Intelligence Agency (CSCIA) employs super paranoid computer spies. In order to communicate with each other, they encode their messages. But they aren’t satisfied with a simple encoding of the messages. Messages are made up of ASCII characters. The binary number for the ASCII character is converted to Excess-127 code. The Excess-127 code is treated as a binary code word and is converted to Gray code, then the Gray code word is encoded using a Hamming code because the transmission lines are noisy. Since ASCII characters are 8 bits, the excess-127 code (and therefore the gray code) could be 9 bits long. This means that the hamming code words will be 13 bits long. Your job is to write the decode procedure. Messages will be received as 13 bit packets (you will need to read from the file, packets.dat that has one packet per line). THERE ARE NO SPACES BETWEEN THE BITS! Your program should read a packet, determine if an error has occurred in transmission, fix any error, extract the gray code message, convert to binary code message, convert the binary to decimal (but remember this is excess 127, so after converting to decimal, you need to take care of that) and print the character. Once the decimal value is determined, you must print the character using ONLY a cout statement (that means no if’s or loops or switches, etc.). Then repeat this procedure for each packet in the file. Your output should contain ONLY the decoded characters plus a single cout <<endl; at the very end of the program. Note: My solution is 61 lines of (non-{}) code, and there was only one if statement that I used to see if there was an error in the hamming code. NO else's, no else-if's, no switches, no ?: operators... LOTS of mod arithmetic, though. :-)
Two sample packets.dat files are shown, but do not download the files. Copy and paste the contents into your data files. Otherwise you get garbage. Huge note: You have no idea what the size will be of my test data file, so you HAVE to read to end of file and do it in the proper manner or you will create an error that is really easy for me to catch.
The code above is converting the gray code to a binary code.
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---