{
  "video_id": "HroTT9ETdqM",
  "channel_slug": "computersciencemadeeasy",
  "channel_handle": "computersciencemadeeasy",
  "title": "Introduction to Gray Code: Practical Applications, Conversion & Binary Comparison",
  "duration_seconds": 1781.0,
  "url": "https://www.youtube.com/watch?v=HroTT9ETdqM",
  "upload_date": "",
  "transcript": "on hello there this is a video session\non what is gray\ncode gray code is a code named after the\nAmerican physicist and researcher Frank\ngreen who worked at the B\nLaboratories this is a non-weighted code\nthat means the position of the bits do\nnot carry any weight so for example we\nare familiar with let us say the binary\nnumber let us take a binary number say\none 1 0 now we know that in this binary\nnumber every bit has an Associated\nweight so if we start with the least\nsignificant bit this has a weight of one\nthis has a weight of two and the next\nbit has a weight of four so as far as\nthe binary number is concerned we say it\nis a weighted code but a gray code is a\nnon weighted code that means the\nposition of the bit does not carry any\nweight\nthis is one of the most important\nproperties of the gray code that means\nthe successive code words or the\nsuccessive codes differ in only one bit\nwe will see how this becomes very\nuseful this is also called as a minimum\nchange code or the unit distance code or\na minimum error code so it is also\ncalled as a minimum change code because\nas we go from one code word to the next\nthere's a change of only one\nbit it is also called a cyclic code\nbecause the words are differing by one\nbit position only as we go from one word\nto the next there's a difference of only\none bit this code is a self-reflecting\ncode this is again an important property\nwhich we will see how it works out how\nwe can use it to generate the complete\ngray\ncode where will this code be used this\ncode is usful in a2d converters or\nanalog to digital converters and it is\nalso used for error detection and\ncorrection in transmission of digital\nsignals and of course we'll be uh\nstudying cornor maps in one of the\nsections and at that time we will see\nthat gray code is extremely\nuseful and since there's a change of\nonly one bit the switching operations\nare reduced and it becomes a power\nefficient code and last but not least\nthis is a very important property this\ncode is not suitable it is not suitable\nfor arithmetic\noperations right okay now let us take up\nthese properties one by one and see how\nthey apply to this particular gray code\nhere we have we have the decimal numbers\nfrom 0 1 to 3 up to 15 we have their\nequivalent binary values in 4bit 0 0 0 0\nand coming to 15 we have 1 1 1 1 now the\ngray code is shown here we will see how\nto generate this gray code but let us\nstudy a few properties of this gray code\nand compare it with the binary\ncode first we saw that gray code is a\nnonweighted code that means the position\nof the bits do not carry any\nsignificance or any\nweight there is a difference of one bit\nin successive codes or it's a minimum\nchange code now let us understand what\nthis particular Point means and to\nunderstand this we'll use the\nexample from this table the decimal\nvalue of three is 0 01\n1 as we go from decimal 3 to decimal 4\nthe binary value of 4 is 0 1 0 0 now you\ncan observe as we go\nfrom 3 to four equivalent decimal values\nthere is a change of three bits for\nexample the bit one has changed to a\nzero this next bit one has also changed\nto a zero and the zero has changed into\na one so as we just move from one\ndecimal digit to the very next decimal\ndigit the three bits of the binary\nnumber out of the four three bits have\nbeen modified but let us compare that\nwith what happens in the case of a gray\ncode so for decimal 3 the equivalent\ngray code is 0 0 1 0 and for four the\ndecimal code is the the equivalent gr\ncode is 0 1 1 0 and you can observe as\nwe go from 3 to 4 the gray code the0 bit\nRemains the Same the one bit Remains the\nSame this zero bit has changed to a one\nbut the next zero bit Remains the Same\nso if you compare these two gray codes\nwhich are of\nsuccessive values then there is a change\nof only one bit and therefore we say\nit's a minimum change code but here in\nwhen you compare it for binary the\nchange in bits was as much as three bits\nchanging at the same time but let us\nobserve that\nself-reflection uh feature\nhere let us consider the first gray code\n000000 and the last gray code which is\nfor decimal number 15 observe that the\nlast three digits of\nthis are Z 0 0 the last three\ndigits of this are 0 0 0 and the\ndifference in the two codes is only in\nthe most significant bit here the most\nsignificant bit is a zero and for this\nthe most significant bit is one look at\nthe next one the next gray code is 00 0\n01 and if you compare it with this it is\n1 0 0 1 again observe\nthese three bits and the last three bits\nhere they are the same and all that is\nchanging is the most significant bit has\nchanged from 0 to\n1 let us take the next one 0\n011 and the third number from the bottom\nit has the gray code 1 1 1 again you can\nsee that three bits here and the three\nbits in this they are the same and only\nthe most significant bit has changed\nfrom a zero to a one and this pattern in\nfact you can observe it as we go to the\nnext pair of bits or the next one and\nobserve it\nhere again in this case the last three\nbits one 1 the last three bits one 1 and\nwhere do the bit patterns differ only in\nthe most significant bit zero has\nchanged to\none and we can observe that here so this\nbecomes a self reflecting\ncode\nnow supposing we have a gray code\nrepresentation of n Bits this n may be\nfor example four bits to obtain the gray\ncode representation for a larger number\nof bits say n + one bits we will write\ndown the two n bit representations one\nbelow the other we'll see this in the\nexample and we will append a zero at the\nbeginning of every code in the first\ngroup and we'll append a one at the\nbeginning of every code in the second\ngroup right and the least and least\nsignificant bits we'll have here now let\nus start this\nexample in this we have a three bit code\nthat is being generated did in the last\ncolumn but let us start from the\nbeginning we start with the two bits 0\nand 1 these two bits you can see they\ndiffer in only one bit and therefore we\ncan say this is the simplest gray code\nthat we can generate which is out of one\nbit now how do I extend this to a 2 bit\ngray code so what we'll do is we'll\nfirst take the original bit 0 and\none these are our original bit 0 and 1\nwe'll create a mirror image of this\npattern so 0 and one so you can imagine\nthat there is a mirror here and we have\nnow generated the mirror image 1 and\nzero so this one its mirror image is one\nhere this zero its mirror image is zero\nnow what we do is we take these four bit\npatterns so we have 0 1 1 0 0 this is 0\n1 1\n0 in front of the pattern which Wass in\nfront of the mirror so we have 0 1 we'll\nappend a 0o so 0 0 so this 0 0 gets\nappended to the part which is in front\nof the mirror as if and coming to the\npart which is the reflection the mirror\nreflection or the mirror image the one\nand the zero these are the ones and the\nzeros that we got we upend this with 1\none and therefore our gray code becomes\n0 0 01 you can see there's a difference\nof only one bit only one bit is changing\nas we move from here to the next 0 1 1 1\nagain this one bit Remains the Same but\nthe zero has changed to a one again 1 1\n1 0 we can observe the one has changed\nto a zero but this one bit Remains the\nSame\nnow we create a mirror image of this so\nthat we can have a three bit gray code\nso how do we do that we take these four\nbits and we write these four bits here 0\n0 0 1 1 1 and 1 0 again we create a\nmirror image of this so\none0 This 1 one becomes a mirror image\nhere 01 comes a mirror image here and\nthe 0 0 becomes the mirror image again\nthe part which is ahead of the mirror or\nthe part which is in front of the mirror\nwe append a zero before that so again\nlet us visualize here is the mirror we\nappend a zero in front so these become\nour bit patterns for the gray code and\nthe part which is uh let us say the\nreflection of the miror image we put a\none and that becomes our GR code in\nthree\nbits this video is dealing with the\ntopic of binary code to gray code\nconversion a binary number can be\nconverted into a gray code by two\ndifferent methods we look at both the\nmethods in this\nvideo the bits of a binary number we can\nrepresent them as a set B 0 B1 B2 B3 as\nwe move from the least significant bit\nto the the most significant bit and\nequivalently the bits of a gray code can\nbe represented with g0 G1 G2 and G3 this\nis of course for a 4bit binary number or\na 4bit gray code now how do we generate\nthe gray code values given a particular\nbinary number the logic will be like\nthis for any given nbit number where I I\nis 0 1 2 3 we say that g of I is the\nexor of the ith bit and the I + one bit\nso for example we'll have G of 0 in this\ncase I becomes z g of 0 will be B 0 + B1\nso the G 0 here and B 0 correspond to\nthe least significant bits of the gray\ncode and the binary code G1 will be B1\nexor with B2 G2 is B2 exor with the next\nhbid which is B3 and G3 is B3 exor with\nB4 this is of course assuming that we\nare considering a 4bit binary number and\nas the bits would be increasing the the\ngray code also would expand accordingly\nnow let us take the first method of how\nto convert a\ngiven binary number into its equivalent\ngray code we are given here the binary\nnumber and that is 0 1 0 1 and that is 0\n1 1 0 now before we start this let us\nshow our truth table this is our exort\ntruth table and as we can see in the\nexort truth table when both the inputs\nare identical a0 b0 the output is zero\nor when A1 B1 the output is again zero\nit is only when the inputs are different\n0 1 or 1 Z and only in these two cases\nonly in these two cases do we get then\noutput of one right so we'll apply this\nlogic to this particular example so let\nus\nstart our first bit is the binary value\nzero now\nthis\nMSB we will first copy it down directly\nand this becomes also the MSP of the\ngray code now from here onwards the\nprocedure will be like this we will take\neach bit of the binary and exort it with\nthe next bit so we'll take 0 XR 1 when\nwe take 0 XR 1 this we know is one then\nwe'll take\none xor\nwith the next bit which is zero so one\nXR with 0o is this will give us one then\nagain 0 xor with one this will of course\ngive us one 1 xor with 0o is\n1 0er xor with one since the bits are\ndifferent this will give us one and now\nobserve here one XR with one this XR\noperation when we carry out 1 XR 1 here\nis\nour Row from the XR table 1 XR one this\ngives us 0\nand 1 XR with 0 gives us 1 and therefore\nour result becomes 0 1 0 1 0 1 1 0 this\nis of binary this is equivalent to 0 1 1\n1 followed by 1 1 0 1 this is of the\ngray code this is how we can\nconvert the binary value into its\nequivalent gray code so here we have\ndirectly used the truth table to do this\nconversion now we have a shortcut we can\nof course refer to this truth table but\nif we observe what this truth table is\nessentially telling us is that when we\ntake two similar values and extort them\ntogether the output is\nzero for example 1 exort one is zero but\nwhen we exort two dissimilar values like\n0 1 or 1 Z in that case the output\nbecomes one and we can use this shortcut\nnot to bring about this conversion so\nlet us take again in this example 0 1 1\n1 0 0 1 0 this is our binary code and\nwe'll convert it into the gray code now\nwe not even refer to this table because\nessentially what this table says is what\nwe'll\nbe making a shortcut here if adjoining\nbits are same we will write a zero and\nif adjoining bits are different we will\nwrite a one so let us start first the\nmost significant\nbit of the binary it is copy it so this\nis\nsimply copy it and it becomes the most\nsignificant bit of the gray code but now\nobserve this compare two bits which are\nsuccessive two adjoining or adjacent uh\nbits so 0o 1 two bits if the joining\nbits are same write zero and if they are\ndifferent write one so these two bits\nare different so we write one again 1\none adjoining bits are same so write a\nzero 1 1 adjoining bits are same write a\nzero 1 0er adjoining bits different so\nthis we put it out as one same adjoining\nbits zero different ad joining bits this\ngives us one and this again is different\nat joining bits this gives us one so\nessentially we have used the same Toth\ntable but instead of referring to this\nevery time we just use a simple logic if\nbits are same adjoining bits are same\nwrite a zero and if adjoining bits are\ndifferent write a one and therefore we\nhave the equivalent gray code\nrepresented by these\nbits now let us take example of\nconverting a decimal number to the gray\ncode now to convert a decimal number to\nthe gray code we must follow two steps\nthe first step is we first convert the\ngiven decimal number to its equivalent\nbinary value so we know this that this\n23 we can convert it into the binary by\nrepeated division by two so this is 2 11\n* is 22 that gives us a\nremainder of one again\n2 5 * is 10 that gives us a remainder\nof 1\n2 2 * is 4 with a remainder of 1\n2 1 * is 2 and there is no remainder and\nnow two since the quotient here is less\nthan 2 2 0 * will be zero and that gives\nus a remainder of 1 and now of course we\ntake\nthese remainders in the reverse order\nand we have 23 of decimal is 1 0 1 1 1 1\n0 1 1 1 and now to convert this bit\npattern into the equivalent gray code we\nagain first copy down the most\nsignificant bit of the\nbinary and that becomes the most\nsignificant bit of the gray code then we\ncompare these two adjoining values if\nthe values are different we write this\nas one again we compare these two\nadjoining values since since these two\nadjoining values are different the\nresult here will be one since these two\nadjoining values are same\nwe write a one we write a zero here\nsince these two adjoining values are\nsame we write a zero here and therefore\n23 of decimal can be written as 1 1 1 0\nin the gray code this is how we convert\na decimal number into a gray code of\ncourse by first going through the\nintermediate state of converting it into\na binary number\nhi welcome to this video session on\nconversion of gray code to its\nequivalent binary\nvalue supposing we are given a gray code\nwhich is\n101101 this is a number we want to\nconvert this into its equivalent binary\nvalue now before we start this we'll\nagain keep our exort Toth table in front\nif a and b are the inputs and we know\nthat a xor b in this case since both A\nand B are zero the output will be zero a\n0 B1 exor value is 1 when a is 1 B is\nzero the XR value is one and again when\nA and B both are identical then output\nis zero so from this truth table we can\nobserve that when a and b are same then\nthe output is zero and when A and B are\ndifferent values the output outut is one\nnow we'll use this to find the\nequivalent binary value so here is the\ngray code that is given to us we write\nthe bits 1 0 1 1 0 1 now the first step\nin finding the binary is we will copy\ndown the bit one that is the most\nsignificant bit of our gray code so this\nis the most significant bit of our gray\ncode we will copy this bit into the most\nsignificant bit of the binary value so\nthis is the MSP of the equivalent binary\nnumber and this which will be simply\ncopied down now from here onwards how do\nwe calculate these bit values so we will\ntake each value that we have obtained\nhere so we will take this value and\nwe'll exort it with the next bit of the\ngray code so one we'll exort it with\nzero so that will give us one so this is\nthe xor operation that we are seeing\nhere 1 xor 0 is 1 again this\none exor with\none that will give us zero because we\nsaw that when both the bits in an exor\noperation are identical then the output\nis zero again\n0o exort with one will give us one this\none\nexort with zero will give us one and\nhere\none exord with one since both bits are\nidentical this will give\nus zero and and therefore we can say\nthat 1 0 1 1 0 1 this is of the gray\ncode so let us just write this subscript\nas GC gray code this is equivalent to 1\n1 01 1 0 1 1 0 1 1 0 this is of the\nequivalent binary\nvalue now in this second example let us\ntake the conversion of 0 1 01 01 into\nits equivalent binary value so here we\nhave again the gray code the bits that\nare given to us 0 1 0 1 0 1 this is our\nmost significant bit and how do we get\nthis binary value let us observe so the\nmost significant bit of the Creer code\nbecomes the most significant bit of the\nbinary so this value is simply copied\ninto the MSP of the binary but\nthereafter 0 exor one we will exort this\n0 with one that gives us one and then\nagain one exord\nwith zero gives us one this one\nexort with one of the gray code this\ngives us 0 0 exord with 0 is again\ngiving us0 because both bits are\nidentical so from our truth shable we\nknow when both bits are identical the\noutput is zero and here we have\nzero exort\nwith one that gives us one and therefore\nwe can say that 0 1 0 1 0 1 of the gray\ncode is equivalent to 0 1 1 0 0 1 of the\nbinary so this is how we convert a gray\ncode into its equivalent binary\nvalue in this third example let us see\nhow we convert a gray code into the\ndecimal number now this will involve two\nsteps in step one we will first convert\nthe gray code into its equivalent binary\nvalue so assuming our gray code is the\nsame as we had in the earlier example 0\n1 0 1 0 1 so we write the gray code bits\n0 1 0 1 0 1 and we convert this into its\nequivalent binary so as we saw in the\nprevious example the m MSP of the gray\ncode is copied and it becomes the MSP of\nthe binary code so this bit has been\ncopied then after that we take the newly\ngenerated bit of the binary and exor\nwith the next bit of the gray code so\nzero exor with\none will give us one this one exor\nwith zero gives us this one so at every\nstep you can see that the new bit that\nis produced in the binary it is exor\nwith the next bit of the gray code so 1\nXR 1 1 XR 1 is zero there we have it\nfrom our XR Toth table 1 xor 1 is 0o so\nwe generate the zero again\n0 xor with 0 so again we have from the\ntruth table 0 XR with 0 is 0 and 0 exor\nwith 1 gives us 1 so we now know that\nthis gray code is equivalent to 011 01\nso this number that we have is the\nequivalent binary value and we know now\nfrom our previous session that we can\nconvert this into the equivalent decimal\nvalue and that becomes 25 so this is 01\n1 0 01 of the decimal we attach a weight\nto each bit so this bit has a weight of\none since the bit here is zero its\ncorresponding weight is two which is\nignored so let us just write the weights\nbelow each so one this will have the\nweight 2 this will have the weight 4\nthis has the weight equivalent weight\n8 this bit has the equivalent weight 16\nand this bit has the equivalent weight\n32 now wherever we have the bit\npositions as zero we ignore the weights\nand then we are left with\n16 plus we have a one bit here so + 8\nand + 1 so that becomes 25 and therefore\nwe say that this equivalent value is 25\nand therefore 0 1 0 1 0 1 of the\ngray code is equivalent to\n25 of decim this is how we convert a\ngray code into its decimal value",
  "transcript_chars": 18793,
  "ingested_at": "2026-05-16T10:33:10.036257+00:00",
  "source": "channel",
  "yt_meta": {
    "view_count": 119,
    "like_count": 1,
    "channel_id": "UC9qXcM_vkJ1ExDv7cCPEgpg",
    "categories": [
      "Education"
    ],
    "tags": [
      "computer science",
      "engineering",
      "Gray code",
      "digital electronics",
      "digital systems",
      "number systems",
      "USA",
      "UK",
      "India",
      "Australia",
      "undergraduate",
      "graduate",
      "education",
      "technology",
      "science",
      "btech",
      "bsc",
      "binary code",
      "digital logic",
      "Interview preparation"
    ]
  }
}