{
  "video_id": "0lnOBgcxNT0",
  "channel_slug": "computersciencemadeeasy",
  "channel_handle": "computersciencemadeeasy",
  "title": "Gray Code - Introduction and Conversions from/to Binary and Decimal",
  "duration_seconds": 1792.0,
  "url": "https://www.youtube.com/watch?v=0lnOBgcxNT0",
  "upload_date": "",
  "transcript": "hello there this is a video session on\nwhat is gray\ncode gray code is a code named after the\nAmerican physicist and researcher Frank\nGRE 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 1\n1 zero now we know that in this binary\nnumber every bit has an Associated\nweight so if we start 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\nnonweighted code that means the position\nof the bit does not carry any weight\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 code word to the\nnext there'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 useful in a TOD 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\nthe decimal numbers from 0 1 to 3 up to\n15 we have their equivalent binary\nvalues in 4bit 0 0 0 0 and coming to 15\nwe have 1 1 1 1 now the gray code is\nshown here we will see how to generate\nthis gray code but let us study a few\nproperties of this gray code and compare\nit with the binary\ncode first we saw that gray code is a\nnon weighted code that means the\nposition of 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 1\nas we go from decimal 3 to decimal 4 the\nbinary value of 4 is 0 1 0 0 now you can\nobserve as we go\nfrom three to four equivalent decimal\nvalues there is a change of three bits\nfor example the bit one has changed to a\nzero this next bit one has also changed\nto a zero and this zero has has changed\ninto a 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\n010 and for four the decimal code is the\nthe equivalent g code is 01 1 0 and you\ncan observe as we go from 3 to 4 the\ngray code the Zer bit Remains the Same\nthe one bit Remains the Same this zero\nbit has changed to a one but the next\nzero bit Remains the Same so if you\ncompare these two gray codes which are\nof\nsuccessive values then there is a change\nof only one bit and therefore we say\nit's a minimum change code but here\nin when 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 here let us\nconsider the first gray code 000000 0\nand the last gray code which is for\ndecimal number 15 observe that the last\nthree digits of\nthis are 0 0 0\nthe 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 0 0\n01 and if you compare it with this it is\n1 0 0 1 again observe these three bits\nand the last three bits here they are\nthe same and all that is changing is the\nmost significant bit has changed from 0\nto\n1 let us take the next one 0 0 1\n1 and the third number from the bottom\nit has the gray code 1011 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 a zero and has\nchanged to one and we can observe that\nhere so this becomes 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\nwe'll see this in the example and we\nwill append a zero at the beginning of\nevery code in the first group and we'll\nappend a one at the beginning of every\ncode in the second group right and the\nleast and least significant bits we'll\nhave here now let us start this\nexample in this we have a three bit code\nthat is being generated 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 1\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 0 and 1\nwe'll create a mirror image of this\npattern so 0 and 1 so you can imagine\nthat there is a mirror here and we have\nnow generated the mirror image 1 and\nzero so this one it's mirror image is\none here this zero its mirror image is\nzero now what we do is we take these\nfour bit patterns so we have 0 1 1 0\nthis is 0 1 1\n0 in front of the pattern which was 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 up this with 1 one\nand therefore our gray code become 0 0 0\n1 you can see there's a difference of\nonly one bit only one bit is changing as\nwe 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 now now we create a mirror image of\nthis so that we can have a three bit\ngray code so how do we do that we take\nthese 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 1\n0 this 1 one becomes a mirror image here\n01 becomes a mirror image here and the 0\n0 becomes the mirror image again the\npart which is ahead of the mirror or the\npart which is in front of the mirror we\nappend a zero before that so again let\nus 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 gray 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 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 in bit number where I\nI is 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 become z g of 0 will be B 0 + B1\nso the g0 here and B 0 correspond to the\nleast significant bits of the gray code\nand the binary code G1 will be B B1 exor\nwith B2 G2 is B2 exor with the next hbid\nwhich is B3 and G3 is B3 exor with B4\nthis is of course assuming that we are\nconsidering a 4bit binary number and as\nthe 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 0 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 we know is one\nthen we'll take\none X or\nwithd the next bit which is zero so 1 XR\nwith zero 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 0o 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 exr table 1 XR one this\ngives us 0\nand 1 exor with 0 gives us 1 and\ntherefore our result becomes 0 1 0 1 0 1\n1 0 this is of binary this is equivalent\nto 0 1 1 1 followed by 1 1 0 1 this is\nof the gray 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 short cut we\ncan of course refer to this truth table\nbut if we observe what this truth table\nis essentially telling us is that when\nwe take two similar values and extort\nthem together the output is\nzero for example 1 exort 1 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\nnow 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'll\nwrite a one so let us start first the\nmost significant\nbit of the binary it is cop 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 there the\nadjoining bits are same write zero and\nif they are different write one so these\ntwo bits are different so we write one\nagain 1 one adjoining bits are same so\nwrite a zero 1 1 adjoining bits are same\nwrite a zero 1 zero adjoining bits\ndifferent so this we put it out as one\nsame adjoining\nbits zero different adjoining bits this\ngives us one and this again is different\nadjoining bits this gives us one so\nessentially we have used the same to\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 the 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\ntwo 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\n0 in the gray code this is how we\nconvert a decimal number into a gray\ncode of course by first going through\nthe intermediate state of converting it\ninto a 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 1 1 1 01 this is a number we\nwant to convert this into its equivalent\nbinary value now before we start this\nwe'll again keep our exort to table in\nfront if a and b are the inputs and we\nknow that that a xor b in this case\nsince both A and B are zero the output\nwill be zero a 0 B1 exor value is 1 when\na is 1 B is zero the xor value is 1 and\nagain when A and B both are identical\nthen output is zero so from this truth\ntable we can observe that when a and b\nare same then the output is zero and\nwhen A and B are different values the\nthe output is one now we'll use this to\nfind the equivalent binary value so here\nis the gray code that is given to us we\nwrite the bits 1 0 1 1 0 1 now the first\nstep in finding the binary is we will\ncopy down 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 bit 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 exor operation that we are seeing\nhere 1 xor 0 is 1 again this\none exor with\n1 that will give us zero because we saw\nthat when both the bits in an exor\noperation are identical then the output\nis zero again\nzero exort with one will give us one\nthis one\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 0 1 1 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 01 01 01 into its\nequivalent binary value so here we have\nagain the gray code the bits that are\ngiven to us 0 1 0 1 0 1 this is our most\nsignificant bit and how do we get this\nbinary value let us observe so the most\nsignificant 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 us zero 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 exord\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 great 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 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 0o\nexor 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 truth table 1 XR 1 is 0o so\nwe generate the zero again\n0 xor with 0 so again we have from the\ntruth table 0 xor 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 two this will have the weight\nfour this has the weight equivalent\nweight\n8 this bit has the equivalent weight 16\nand this bit\nhas the equivalent weight 32 now\nwherever we have the bit positions as\nzero we ignore the weights and then we\nare 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": 18820,
  "ingested_at": "2026-05-16T10:33:16.784212+00:00",
  "source": "channel",
  "yt_meta": {
    "view_count": 88,
    "like_count": 2,
    "channel_id": "UC9qXcM_vkJ1ExDv7cCPEgpg",
    "categories": [
      "Education"
    ],
    "tags": [
      "computer science",
      "engineering",
      "Gray code",
      "convert from decimal to gray code",
      "convert from binary to Gray code",
      "scitechgen",
      "computer engineering",
      "information technology",
      "bca",
      "mca",
      "bsccs",
      "bscit"
    ]
  }
}