Free Essay

Gray Code

In:

Submitted By debarpandan
Words 1010
Pages 5
What is Gray code?

From Wikipedia
The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only one bit.

The reflected binary code was originally designed to prevent spurious output from electromechanical switches. Today, Gray codes are widely used to facilitate error correction in digital communications such as digital terrestrial television and some cable TV systems.

One good way to explain the use of Gray code is to take a look at how a hard drive work, in extreme simplicity.
A hard drive contains a disc where information is stored. The information on the disc is stored in ones and zero´s, binaries. The disc is divided into sections which each has a binary signature.

Here is a picture to explain:

As we can see here, section 0 for example has the binary signature 0000 and section 15 has the binary signature 1111. When a hard drive is running it reads section by section and if the hard drive for some reason has a failure and the reader jumps from section 15 to section 0 the reading changes from 0000 to 1111 which means that every bit read is faulty.
This could change alot depending on how the information is parsed.

A hard drive could be exposed to a lot of external forces and the reader can jump and missread at any time. This cannot be forseen, but it can be prevented to some extent.
Enter Gray code.

Gray code is a way to sort the binaries so that one binary never differs more than one bit from another. This is good news compared to the drastic differance between 0000 and 1111.
If we look at a 4-bit value in ordinary binary form and in Gray code form we can see some patterns. The changes in each binary string is bolded:
Decimal Binary Gray code
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000

There is a pattern that emerges here. The digit that changes in the regular binary string is the same that changes in Gray code.

If we look at how a Gray code hard drive would look we can see that this hard drive looks a lot different than the ordinary one:

Note: Gray code is small, red font, ordinary binary code is in black

This doesn't seem to make sense. The ordinary hard drive is ruled by the regular binary pattern where each section has the same binary value as it's section value. The Gray code seems to have no pattern at all.

Let's first look at why it makes sense:
If you look at the difference between each section you can see that there is never more than one bit that differs from the previous and upcomming section. Quite weird, but very effective when it comes to error handling.

Is there a pattern?
Of course there is . Anything else would be silly. The pattern however is not as easy to see as the normal binary pattern where you can just look at it's numerical counterpart and do the math.
In the Gray code circle we can look at section 5 for example. The regular binary value is 0101 which we can quickly see is 5. The Gray code value however is 0111 which should be 7 in decimal, how strange.
With gray code we will have to accept a new way to do the math. First, let's understand how we get the Gray coded binaries.
Gray code is decided by bitwise operations with XOR. The XOR operator works like this: if two values are the same the result is false, if the two are different the answer is true. This chart can explain it:

Value 1 XOR Value 2
Value 1 Value 2 Answer
True False True
True True False
False True True
False False False

Read more about XOR here.

Now that we know how XOR works we can convert regular binary string 0011 (decimal 2):

We check each bit, starting from the right, with the next one:

1 XOR 1 = 0
1 XOR 0 = 1
0 XOR 0 = 0
0 XOR 0 = 0

As we can see, all of a sudden 0011 turns into 0010. Hopefully this somewhat explains what Grey code is and how it works and is used.

C# Gray code generator

If you're interested in C# programming you might find this helpful in order to explain how to calculate Gray code.

We will make a console application that converts regular binaries into Gray code binaries. It will output them next to each other so to visualize the difference, it will look like this:

Now, there are easy ways to convert decimals to binary and binaries to Gray code and there are hard ways. If you want an easy way out you can read my blog on the subject here.
This program will do it the hard way

First, we're gonna need two arrays that can hold 16 values. string[] binaries = new string[16];

string[] grays = new string[16];

The hard way of converting decimal values to binaries is to use modulus. What we do is that we take the number to convert and divide it by two. If there is a remainder, we add a 1, otherwise a 0.
As an example we can try it out on the number 3, that we know must be 0011 in binaries:

3 % 2 = 1
1 % 2 = 1
0 % 0 = 0
0 % 0 = 0

Funny thing here. We seem to have a remainer after the second step as well, but since we run this integer style we round down. But since there was a remainder we add a 1 to the binary.

The C# code to create binaries thus looks like this:

Similar Documents

Free Essay

Aasdfa

...Search Binary numbers addition is straight forward process while binary subtractions involve three fundamentals. VHDL Test Benches Generate VHDL models from timing diagrams or logic analyzer data. www.syncad.com Binary Numbers 1s_complement 2s_complement Binary Subtraction Binary Sub. Ex's Sign_magnitude SignM EX Gray Coding BCD coding Digital gates NAND NOR & XNOR Theorems Boolean Functions BFunc Examples Minterm Maxterm Sum of Minterms Prdt of Maxterms 2 var K-map 3 var K-map 4 var K-map 5 var K-map Prime Implicant PI example K-map Ex's KMap minimization Binary Subtraction: Suppose, M is Minuend and N is subtrahend Then, M – N can be done based on following three steps: Step 1: Take 2’s complement of N and add it to M. M – N = M + (2^n – N) Step 2: If M is greater than or equal to N then end carry is discarded from the result M –N = M + (2^n – N) – 2^n Step 3: If M is less than N then take 2’s complement of the result and append negative ‘-‘ sign in front M-N = (-) [2^n – (M + (2^n -1))] Example 1 : Perform binary subtraction of two binary numbers M = 10101010 and N = 00111000 M–N 10101010 - 00111000 End carry 1 01110010 Resources Verilog RTL code examples for front-end chip design. Digital Design Topics Half-adder, full-adder, Adder-sub tractor Stack Organization - LIFO, RPN Parity Generation and error checking Binary multiplier circuit. CMOS introduction Digital fundamentals RTL coding guidelines. ICG cell,...

Words: 667 - Pages: 3

Free Essay

Essay on Gray Code

...Artificial Intelligence – Depth First Search(DFS) November 13, 2012 · by Siddharth Agrawal · in Artificial Intelligence Okay! So this is my first blog post! I will start by talking about the most basic solution to search problems, which are an integral part of artificial intelligence. What the hell are search problems? In simple language, search problems consist of a graph, a starting node and a goal(also a node). Our aim while solving a search problem is to get a path from the starting node to the goal. Consider the diagram below, we want to get to the node G starting from the node S. Which path will we get on solving the search problem? How do we get the path? This is where algorithms come into picture and answer all our questions! We will look at Depth First Search which can be seen as a brute force method of solving a search problem. Creating the search tree So how do we simplify this problem? If we reduce the graph structure to a tree(not particularly a binary tree!), the problem would be to find a node with a particular value starting from the root. So the tree would be as follows: S will be the root of the tree. S will have children A and G. A will have children B and C. B will have only one child D. C will have children D and G. D will have only one child G. Now you may ask which ‘D’ will have the child G, the one which is the child of B or the one which is a child of C? The answer is both. We want to consider all the possibilities and thus we have to show all the connections...

Words: 797 - Pages: 4

Free Essay

Htdfd

...CCE220-Section B: Digital Systems Mr. Michel Owayjan (Beirut) AMERICAN UNIVERSITY OF SCIENCE & TECHNOLOGY FACULTY OF ENGINEERING DEPARTMENT OF COMPUTER AND COMMUNICATIONS ENGINEERING CCE 220: Digital Systems Spring Term 2013-2014 INSTRUCTOR CLASS HOURS Mr. Michel Owayjan MWF Room: 3:00 pm - 3:50 pm 404, Block B OFFICE HOURS M-W-F 2:00 pm - 3:00 pm T-TH 12:00 am - 1:00 pm Otherwise by appointment Room: 805, Block A COURSE OBJECTIVES This is a sophomore-level course which addresses the fundamentals of digital systems needed to develop the ability of the student in understanding the concepts related to this area of engineering. The objective is to train the students on the various tools used to solve problems related to the design of digital systems. These include: i) binary number system; ii) conversion between number systems; iii) Boolean algebra; iv) logic gates; v) Karnaugh maps; vi) combinational and sequential logic; vii) SSI and MSI design; viii) flip-flops; ix) counters; x) registers; xi) memories; and, xii) state machines. The problem solving and experimental skills of the student in the above areas are enhanced by a co-requisite Laboratory Course held on a weekly basis. COURSE PREREQUISITES CSI 201: Introduction to Computing PREREQUISITES BY TOPICS The student should have the general background in computers and algebra. COURSE CREDITS 3 Credit Hours INSTRUCTION TECHNIQUE Lectures will be used predominantly. These will be supported by problem sets...

Words: 1685 - Pages: 7

Free Essay

Pearls

...5 Gauss line = 5 mT = 0.005 T Average background radiation dose to US citizen = 300 mrem Consider therapeutic abortion if dose to fetus > 10 rad (0.1 Gy) To categorize area as restricted from general public, average dose rate > 2 mrem/hr If Tc99m is given to lactating female, cease breast-feeding for 4 days Terminate breast-feeding altogether after administration of I131 or Ga67 Test for Mo99 contamination in Tc99m samples by using a dose calibrator Use thin layer chromatography to test for free Tc in Tc99m Use colorimeter to test for Al in Tc99m MDP White label I < 0.5 mrem Yellow < 50 mrem/hr – AND – not > 1 mrem/hr @ 1 meter Yellow III > 50 mrem/hr – OR – > 1 mrem/hr @ 1 meter Maximum allowable exposure to family members of patients with I131 = 5 mSv Risk for congenital defects from radiation to general population significantly increases > 15 rad (150 mGy) Radiotherapy dose must be > 20% to report to NRC A well counter does not use a gas-filled chamber to detect radiation levels Mo99/Tc99m generator operates on principle of transient equilibrium and is state where daughter radionuclide is short than that of parent radionuclide In secular equilibrium, radioactive daughter’s decay rate is balanced by own decay rate Risk of congenital defects to fetus significantly increases > 100 mGy Annual occupational dose equivalent limit to single organ in radiation worker = 50000 mrem (500 mSv). NaI123 has t1/2 = 13.2 hr Theraspheres used...

Words: 373 - Pages: 2

Premium Essay

American Quarter Horse Research Paper

...Lauren Sims Mrs.Cordon Literature October 10, 2014 The American Quarter Horse Some horses are great at jumping, some at dressage, and some at western, but did you know there is one horse that can do it all? The American Quarter Horse, also known as the “Do it all horse”, can really do it all! They can do everything from racing, jumping, and dressage, to reining, barrel racing, and other rodeo events. That is why the American Quarter Horse is the most popular breed in the U.S! Please keep reading to learn more about the American Quarter Horse. When the Spanish explorers came to America in the 16th century they brought their horses. The Spanish horses were called Jennets. Jennets were short, stocky, and muscular. Although they were short, they were quick, dependable, and very intelligent. The population of Jennets increased and increased. The Spanish would either keep them for herding cattle or trade them to Native American tribes that would use them for hunting. Some jennets were wild and are called mustangs. In the 17th century the English came to America, they built colonies along the east coast and they also brought their horses. The English horses are called Thoroughbreds. They were tall, skinny, had long legs, and were also very fast. The Thoroughbreds also had a lot of work, they were saddled for long rides, used for pulling plows, heavy loads, and sometimes hitched to wagons. It wasn't long after the Thoroughbreds arrived that they started breeding them with the jennets...

Words: 669 - Pages: 3

Free Essay

Ct Essay

...Importance of Radiation Safety in Computed Tomography Advances in computed tomography (CT) technology have continued to open new clinical applications, including several procedures for evaluating heart disease. The speed with which CT technology is changing is somewhat unparalleled in medical imaging. The equipment is becoming faster and faster. In the 1990s, a patient had to remain in a CT gantry for a period of approximately 10 minutes for a chest CT, whereas now it takes a few seconds to scan the entire chest. This may give the impression that radiation dose in CT is small, which is not the case. To give an example, a typical chest CT can impart a radiation dose equivalent to hundreds of chest radiographs. The offshoot of higher speed is that shoulder to pelvic scans or even head to pelvic scans are becoming more common, and this is raising questions of justification. Repeat scans on the same patients are also not uncommon. It is becoming clear that many CT examinations (typically one third) are unjustified and can be avoided through appropriate clinical judgment. There is no doubt that newer technology has increased the usefulness of CT examinations in areas where earlier there was little justification of CT. It has been documented that radiation dose to the patient can be reduced significantly through optimization actions. However, repeated examination on the same patient, or examination on a child or pregnant woman, requires a higher level of attention to radiation...

Words: 479 - Pages: 2

Free Essay

Asdfsaf

...PARENTING STYLES Developmental psychologists have long been interested in how parents impact child development. However, finding actual cause-and-effect links between specific actions of parents and later behavior of children is very difficult. Some children raised in dramatically different environments can later grow up to have remarkably similar personalities. Conversely, children who share a home and are raised in the same environment can grow up to have astonishingly different personalities than one another. Despite these challenges, researchers have uncovered convincing links between parenting styles and the effects these styles have on children. During the early 1960s, psychologist Diana Baumrind conducted a study on more than 100 preschool-age children (Baumrind, 1967). Using naturalistic observation, parental interviews and other research methods, she identified four important dimensions of parenting: * Disciplinary strategies * Warmth and nurturance * Communication styles * Expectations of maturity and control Based on these dimensions, Baumrind suggested that the majority of parents display one of three different parenting styles. Further research by also suggested the addition of a fourth parenting style (Maccoby & Martin, 1983). The Four Parenting Styles 1. Authoritarian Parenting In this style of parenting, children are expected to follow the strict rules established by the parents. Failure to follow such rules usually results in punishment...

Words: 4242 - Pages: 17

Free Essay

Marketing for Arabians Ltd

...Shaunya Fraysher Arabians LTD began as a tax deduction with five Straight Egyptian Arabian mares used for breeding in the 1970s. This company has become the world’s leading breeder of these rare horses. Arabians LTD enjoys annual net income of approximately 1 million dollars, not bad for a couple who started out looking for a tax break. Currently they market mostly oversees in Israel, Egypt, Saudi Arabia, and other countries in the Mid-East. Here in America their marketing is limited to Arabian horse magazines. This is the most efficient marketing campaign for the company at this time; however, I see opportunities for advancement. Egyptian Arabians are so rare that if not for being in captivity they would be on the endangered species list. This breed is the oldest know horse, both archeologically and recorded breeding, in the world. After all, who has not admired the hoses of the Pharaohs? Every horse must be able to have its ancestry traced to the Egyptian desert, wild caught prior to the early 1800s. No intentional breeding for physical characteristics other than that of the originals is permitted. In 2006, there were 17,000 true SE Arabians in the world. Using this as a marketing strategy here in the US could potentially bring in new investors who might invest for this reason. Expanding the advertisements into other horse magazines, web sites, and social media adds expressing the need to save this breed could potentially bring in financing or purchasers wanting to help “save”...

Words: 903 - Pages: 4

Free Essay

Full Size or Compact

...Full Size or Compact The love people have for horses have been around for centuries. There are many breeds of horses; the most popular is the Quarter Horse. Over the years a smaller breed of the Quarter Horse has emerged, the Quarter Pony. There is certain criteria a Quarter Horse must have, the Quarter Pony must meet certain criteria, and since the Quarter Pony comes from the Quarter Horse breed the two are alike and different. Even though the Quarter Pony is a small replica of the Quarter Horse, the Quarter Horse is one of the most recognized horse breeds in America. The Quarter Horse has certain criteria it must have to be considered for registration with the American Quarter Horse Association (AQHA). The following is some of the AQHA regulations that are required (AQHA, 2011). The horse must be 14.2 Hands High (HH) or taller, but not over 15.3 HH, must be from a bloodline of registered Quarter Horses (mother and father must be registered with the AQHA), the horse must be one of the 17 basic Quarter Horse coat colors, and must be tall, muscular, lean, and fast. The quarter Pony has certain criteria it must meet to register with the International Quarter Pony Association (IQPA). The following is some of the IQPA regulations that are required (IQPA, 2011). The horse is required to be under 14.2 HH and over 11.2 HH, must come from one parent that is registered with the AQHA (the mother or father must be registered with the AQHA), the horse does not have to be one...

Words: 512 - Pages: 3

Free Essay

Msom Ppt

...RAD 205 Scoliosis Problem Set 9/23/13 In RAD 205 you will be provided with an example calculation of the organ dose to a patient’s liver for one PA projections for scoliosis. The example assumes the exposure was made with 50 mAs at 90 kVp. For this Problem Set, recalculate the organ dose assuming the exposure was made with 20 mAs at 90 kVp. This assignment is organized into a series of problems. Each problem is worth 3 points (one point for correct equation, one for correct work, and one for the final answer). The example problem below illustrates what is expected. This example problem would earn 3 of 3 possible points. Example problem: If an exposure is measured at 25 milliRoentgen, what is the exposure in units of Roentgen? Equation(s): Show your work: State your answer: The problems that you are to solve are listed below. Refer to the class handout titled “RAD 205 Effective Dose to Patients in Diagnostic Radiography” as you work through these problems. 1 RAD 205 Scoliosis Problem Set 9/23/13 Problem 1. What is the Entrance Skin Exposure? Refer to page 3 of the handout and show your work on the nomogram at right. Equation(s): none for this problem. Use the nomogram instead of an equation. Show your work: Use a straight edge to draw a line starting at 90 kVp on the axis at the far right and ending at approximately 20 mAs at the axis on the left. Find the point at which your line crosses the axis in the middle (ESE). Read the approximate ESE...

Words: 415 - Pages: 2

Free Essay

This Is Wonderful

...Consumer Information FCC Notice This equipment has been tested and found to comply with the limits for a Class B digital device, pursuant to Part 15 of the FCC Rules. These limits are designed to provide reasonable protection against harmful interference in a residential installation. This equipment generates, uses and can radiate radio frequency energy and, if not installed and used in accordance with the instructions, may cause harmful interference to radio communications. However, there is no guarantee that interference will not occur in a particular installation. If interference generated by this unit is suspected, call Brink’s Customer Care at 1-800-445-0872. If this equipment does cause harmful interference to radio or television reception, which can be determined by turning the equipment off and on, the user is encouraged to try to correct the interference by one or more of the following measures: ♦ Re-orient the radio/television antenna; ♦ Move the television or receiver away from the unit. ♦ Plug the unit and the TV/radio receiver into different outlets, i.e. not on the same circuit breaker. ♦ Contact Brinks Home Security or an experienced TV/Radio technician for additional suggestions. ♦ Review additional instructions on www.mybrinks.com. This equipment complies with FCC Rules, Part 68. On the outside of this equipment is a label that contains, among other information, the FCC Registration Number and Ringer Equivalence Number (REN) for this equipment. If requested...

Words: 10912 - Pages: 44

Free Essay

Content Analysis

...collected. * Many respondents presented more than one thought or feeling. In some cases they described a sentence to capture the imagery in the pictures. * In such cases all individual thoughts and feelings were captured for coding process * Coding Scheme: - The coding scheme that was obtained is as below (in alphabetical order). Please observe the ads you would find how the below codes were developed. SNo | Code | 1 | Adventure sports | 2 | Business | 3 | Celebrity testimonial | 4 | Dance | 5 | Do’s and Don’ts | 6 | Fashion | 7 | Food | 8 | Festivales | 9 | Food | 10 | Handicrafts | 11 | History | 12 | Hospitality | 13 | Nature | 14 | Natural Landscape | 15 | Monuments | 16 | Music | 17 | People | 18 | Public Awareness | 19 | Religion | 20 | Shopping | 21 | Spirituality | 22 | Sports | 23 | Wellness | 24 | Wildfire | * Theme generation: - Seven themes were identified based on the coding schemes. The list of themes are as below Sno | Code | Theme | No of Ads | 1 | Fashion | Culture(that broadly describes the codes presented in previous column. | 15 | 2 | Festivals | | | 3 | Dance | | | 4 | Food | | | 5 | Handicrafts | | | 6 | Hospitality | | | 7 | Music | | | 8 | People | | | 9 | Religion | | | | | Flora | 9 | 10 | Nature | | | 11 | Natural Landscape | | | 12 | Wildlife | | | | | | | 13...

Words: 294 - Pages: 2

Premium Essay

Case Study: How ICD-10 Impacts Healthcare

...The World Health Organization established the International Classification of Diseases (ICD) to standardize medical records. ICD-10 is an update that reflects changing needs in medicine. The code offers increased detail and flexibility. However, implementing the code presents medical establishments with several challenges. The biggest challenge is finding common ground between the two frameworks. How ICD-10 Impacts Healthcare A presentation published by the Centers for Medicare and Medicaid Services explains that the World Health Organization created ICD-9 in 1979 to reflect current medical advances and establish universal coding procedures. [1] The system outlines the diagnoses, procedures and terminology used by caregivers. Medical organizations...

Words: 937 - Pages: 4

Premium Essay

Unit 9 Vs Icd-9

... ICD-9 has approximately 13,000 codes that are V.S. ICD-10 has about 68,000 codes and are 3 3 to 5 digits. to 7 digits long. ICD-9 first digit is either E or V or numeric ICD-10 first digit is alpha; 2nd and 3rd are numeric; 4th thru 7th are either ICD-9 lacks detail...

Words: 720 - Pages: 3

Premium Essay

Hsc300 Unit 3 Assignment

...Shelly reviewed the updates made to the Carrier Form Codes. • The Carrier Services and Agent Reporting Agreement were updated effective June 15, 2015 to allow the settlement of carrier form codes. • Based on carrier request and ARC approval, ARC will update our form code table in alignment with the carrier’s form code range to prevent transaction errors and duplicate usage in IAR. • Testing may need to be performed. • Carriers should initiate their requests through ARC’s Carrier Help Desk or Shelly Younger. The preference would be to begin with Shelly Younger. • ORION is a multi-year project which will modernize the current settlement system. Work will occur in five phases. • Phase I – Foundation for Travel Agency, Carrier and Credit...

Words: 578 - Pages: 3