Understanding BCD and Gray Codes
Understanding BCD and Gray Codes
Decimal encoded in
Binary
1 BCD Code. Binary Coded Decimal 2Aiken BCD Code– Excess-3 BCD Code
3Gray Code4Binary Conversion– GRAY and GRAY– Binary
The BCD code uses 4 binary digits (see in the two examples that follow) to represent
a decimal digit (0 to 9). When converting from binary to decimal typically there is no...
direct relationship between the decimal digit and the binary digit.
Example 1: Typical direct conversion between a number in decimal and onebinary. 8510=
10101012The representation of the same numberdecimalBCD code is shown to the
right.
Example 2: Typical direct conversion between a decimal number and a binary one. 56810=
10001110002The representation of the same decimal number in BCD code is shown at the
right.
As can be seen, from the two previous examples, the equivalent decimal number is not
it looks like the representation in BDC code. In order to obtain the equivalent code
In BCD, each digit of the previous numbers is assigned a 'weight' or 'value' according to its position.
what occupies. This 'weight' or 'value' follows the following order: 8 - 4 - 2 - 1. (It's a code
weighted). From the last example, it is observed that the number 5 is represented as: 0 1 0 1.
The first '0' corresponds to 8, the first '1' corresponds to 4, the second '0' corresponds to 2,
and the second '1' corresponds to 1. From the above: 0 x 8 + 1 x 4 + 0 x 2 + 1 x 1 = 5
The BCD code that has the 'weights' or 'values' described above is called: BCD code
Natural. The BCD code counts like a normal binary number from 0 to 9, but from ten (1010)
The fifteen (1111) are not allowed because there is no equivalent of a for these numbers.
decimal figure. This code is used, among other applications, for the representation of
the figures of decimal numbers inseven-segment displays.
Notes: The subscripts 2 and 10 are used to limit, in the first case that the number is
binary and in the second case that the number is decimal.
Numbering Systems
Construction of a BCD Counter
Gray Code
It is a code designed to minimize errors during the transition between a
value of code and another. This code changes only one bit between two values
sequential. It is used in axis encoders and other applications where
mechanical control that uses digital code, requires minimizing the stresses that
could occur if an erroneous value were sent during the transition. The rule for
to generate this code is: it starts with all zeros, and only the bit is changed
less significant needed to represent a new state.
Gray code
Gray code belongs to a class of minimal change codes, in which only one bit of
The code group changes when it moves from one stage to the next. Gray code is a code
useless, that is, the positions of the bits in the code groups have no value
specific assigned to them. Due to this, the code does not conform to arithmetic operations but
that there are applications in input and output devices and some types of converters of
analog to digital.
The following table shows the Gray code representation of the decimal numbers from 0 to
15, along with the direct binary code. If we examine the groups in Gray code to observe
each decimal number, it can be observed that when moving from any decimal number to
next, only one bit of the Gray code changes. For example, when going from 3 to 4, the Gray code
change from 0010 to 0110 and only change the second bit from the left. When going from 14 to 15 the bits of
Gray code changes from 1001 to 1000 and only the last bit changes. This is the characteristic.
principal del código de Gray. Comparemos esto con el código binario, donde cualquier parte,
from one to all the bits, changes as it moves from one stage to the next.
Gray code is used in situations where other codes, such as binary, could
produce erroneous or ambiguous results during those transitions where more than one bit of
the code changes. For example, when applying binary code and going from 0111 to 1000, it requires that the
four bits change simultaneously. Depending on the device or circuit that generates the bits, it can
there is a significant difference in the transition times of the different bits. If so, the
Transitioning from 0111 to 1000 could produce one or more intermediate states. For example, if the most
significant change happens faster than the rest, the following transitions will occur:
The appearance of 1111 is only momentary but could conceivably lead to an operation.
erroneous of the elements that are controlled by the bits. Clearly, the use of Gray code
I would eliminate this problem, since only a bit change occurs per transition and there cannot be
hierarchies among the bits.
In summary, the main advantage of using Gray code is its application in situations where
which other codes, like binary, could produce erroneous or ambiguous results
during those transitions in which more than one bit of the code changes.
The reflected binary code was applied to math puzzles before being used for the
engineering. The French engineer Émile Baudot applied the Gray code in 1878 in
telegraphy, work for which he was awarded the Legion of Honor.
Until the first half of the 1940s, digital logic circuits were made with valves.
empty and electromechanical devices. The counters needed very high powers to the
input and generated noise spikes when several bits changed simultaneously. Taking
taking this into account, Frank Gray invented a method to convert analog signals into groups of
reflected binary code using a device designed with vacuum tubes, which guaranteed
that in any transition only a bit would vary.
Currently, Gray code is used as part of the design algorithm for maps of
Karnaugh, which are, in turn, used as a "design tool" in the implementation.
of combinational circuits and sequential circuits. The relevance of Gray code is due to the fact that a
efficient digital design will require simpler and faster transitions between logical states (0 or 1),
that is why its use persists, despite the issues of noise and power being
reduced with solid-state technology of integrated circuits.
Using Gray code, it is also possible to solve the problem of the Towers of Hanoi. It can be
even forming a Hamiltonian cycle or a hypercube, in which each bit can be seen as a
dimension.
The following table shows the Gray code representation of the decimal numbers from 0 to
15, along with the direct binary code. If we examine the groups in Gray code to observe
for each decimal number, it can be observed that when moving from any decimal number to the next,
only one bit of the Gray code changes. For example, when going from 3 to 4, the Gray code changes from
0010 to 0110 and only change the second bit from the left. When going from 14 to 15 the bits of the code of
Gray changes from 1001 to 1000 and only the last bit changes. This is the main characteristic of the code.
of Gray. Let's compare this with binary code, where any part, from one to all
bits change when moving from one stage to the next.
Gray code is used in situations where other codes, such as binary, could produce
erroneous or ambiguous results during those transitions in which more than one bit of the code
change. For example, when applying binary code and moving from 0111 to 1000, it is required that the four
bits change simultaneously. Depending on the device or circuit that generates the bits, there can be a
significant difference in the transition times of the different bits. If so, the transition of
0111 to 1000 could produce one or more intermediate states. For example, if the most significant
change but fast what the remaining,will occur the following transitions:
The appearance of 1111 is only momentary but could conceivably produce an operation.
erroneous of the elements that are controlled by the bits. Clearly, the use of Gray code
I would eliminate this problem, as it only involves a single bit change per transition and there cannot be
"hierarchies" among the bits.
In summary, the main advantage of using Gray code is its application in situations where
other codes, such as binary, could produce erroneous or ambiguous results during
those transitions in the which more of a bit of code change.
The reflected binary code was applied to mathematical puzzles before being used for the
engineering. The French engineer Émile Baudot applied Gray's code in 1878 in
telegraphy, work for which he was awarded the Legion of Honor.
Until the first half of the 1940s, digital logic circuits were made with vacuum tubes.
empty and electromechanical devices. The meters required very high powers to the
input and generated noise spikes when several bits changed simultaneously. Taking this
Please note, Frank Gray invented a method to convert analog signals into groups of code.
reflected binary using a device designed with vacuum tubes, thereby ensuring that in
any transition would vary by just one bit.
Currently, Gray code is used as part of the design algorithm for maps of
Karnaugh, which are, in turn, used as a "design tool" in the implementation.
of combinational circuits and sequential circuits. The relevance of the Gray code is due to the fact that a
efficient digital design will require simpler and faster transitions between logical states (0 or 1),
that is why it continues to be used, despite the noise and power problems that have arisen
reduced with solid-state technology of integrated circuits.
Using Gray code, it is also possible to solve the problem of the Towers of Hanoi. One can
even form a Hamiltonian cycle or a hypercube, in which each bit can be seen as a
dimension.
Thelaws(orrules)ofKirchhoffwereformulatedbyGustavKirchhoffin1845.
[Link]
obtainthevaluesofthecurrentandthepotentialateachpointinacircuit
[Link].
Theselawsallowustosolvecircuitsusingthesetofequations.
[Link],yougottoknowtheLWvirtuallaboratory.
Elfuncionamientodeesteydetodosloslaboratoriosvirtualesconocidossebasa
intheautomaticresolutionofthesystemofequationsgeneratedbyacircuit
[Link],thePCpresentsascreenthatresemblesa
electroniclaboratorybutasbackgroundworkitisactuallysolving
[Link]
suchspeedthatitcandisplaytheresultsonthescreenwithaspeed
similaralthoughnotequaltotherealoneandinthiswayobtaingraphsthatsimulatethe
functioningofanosciloscope,whichisaninstrumentintendedtoobserve
tensionsthatchangerapidlyastimegoesby.
Inthisdelivery,wewilexplainthetheoryinaclassicalwayandatthesametime
wearegoingtoindicatehowtoperformtheverifcationofthattheoryinthevirtualaboratory
LW.
Inanelectricalcircuit,[Link]
thepointinthecircuitwheremorethanoneterminalofanelectricalcomponentjoins.
Ifyouwish,pronounce"nodo"andthinkof"nudo"becausethatispreciselythe
reality:twoormorecomponentsarejoinedtiedtogether(actuallysoldered
betweeneachother).Infigure1,themostbasicoftheDCcircuitscanbeobserved.
(directcurrent)thatcontainstwonodes.
Fig.1Basiccircuitwithtwonodes
Notethatthesearetwo1Kohmresistors(R1andR2)connectedovera
samebatteryB1.ThebatteryB1maintainsitsfixedvoltagedespitetheload
imposedbythetworesistors;thismeanseachresistorhasaappliedone
[Link]'slawstatesthatwhena1Kohmresistorisapplied
Avoltageof9Visapplied,andacurrentof9mAflows.
I=V/R=9/1.000=0.009A=9mA
Therefore,wecanassurethateachresistorwiltakeacurrentof9mA.
[Link]
wecouldsaythataconductorcomesoutfromthebatterythroughwhich18mAcirculates
thatuponreachingnode1itsplitsintoacurrentof9mAthatflowsthrougheach
resistor,sothatatnode2theycometogetheragaintoreturntothebatterywith
avalueof18mA.
Fig.2ApplicationofthefirstlawofKirchoff
Thatistosaythatatnode1wecansaythat
I1=I2+I3
andreplacingvalues:that
18mA=9mA+9mA
and in node 2
I4 = I2 + I3
ItisobviousthatcurrentsI1andI4areequalbecausewhatexitsfromthebattery
itmustbethesameaswhatisentered.
StarttheLW.Drawthecircuitoffigure2.ThenpresstheF9keyonyourPCto
[Link],wearenotgoingto
[Link]
CurrentFlowmarkedwilobserveacartoonwiththecurrentsflowingand
bifurcatingateachnode.
Toknowthevalueofthecurrentthatflowsthrougheachpointofthecircuitandthe
tensionwithreferencetothenegativeterminalofthebattery,doesnotneedtoconnect
[Link]
connectionleadsandtheLWwilgenerateasmallwindowindicatingVandI
[Link]
previouslyarethecorrectones.
Tostopthesimulation,youjustneedtopresstheControlandF9keysonyourPC.
sametime.
Theincomingcurrenttoanodeisequaltothesumoftheoutgoingcurrents.
Inthesameway,thefirstlawofKirchhoffcanbegeneralizedbysayingthatthesumof
Theincomingcurrentstoanodeareequaltothesumofthecurrents.
outgoing.
Thereasonwhythislawisfulfiledisperfectlyunderstoodinform.
intuitiveifoneconsidersthatelectriccurrentisduetothecirculationof
[Link]
circuitinwhichtheresistorshaveavaluemuchgreaterthantheindicatedone,
sothataverysmallelectriccurrentcirculates,consistingofonly
[Link]
[Link]
Atacertainpoint,theelectronsrealizethattheelectricalresistanceistowardsboth.
Resistorsarethesameandthentheyaredivided,with5goingthroughoneresistorandtheother5.
[Link].
youcanonlydistributethemfromthecircuitanddosobasedonthe
[Link],theresistancesareequaland
[Link]
iftheywerediferent,maybe1electroncouldcirculatetowardsoneandninetowardstheother
anotheraccordingtotheapplicationofOhm'slaw.
Butscientificallywecouldsaythatalawofmustalwaysbefulfiled.
physicsthatsaysthatenergyisneithercreatednordestroyed,butisalways
[Link]
methodthattransformsintoequalthermalenergiesdeliveredtotheenvironmentby
[Link]
sametension,theymustgeneratethesameamountofheatandthereforemust
beingtraversedbythesamecurrent;thatwhenadded,mustbeequaltothe
currentdeliveredbythebattery,tocomplywiththelawofconservationof
energy.
Inoneword,thattheelectricalenergydeliveredbythebatteryisequaltothesum.
[Link]
[Link]ínFierrosays,everyWattthatwalksgoesto
[Link]:theWattistheunitofelectricalpowerandwilbestudied
opportunely.
Whenacircuithasmorethanonebatteryandseveralloadresistors,itnolonger
[Link],itisof
applicationofthesecondlawofKirchhoff,whichallowsustosolvethecircuitwitha
greatclarity.
Inaclosedcircuit,thesumofthebatteryvoltagesthatarepresentat
traversingitwilalwaysequalthesumoftheexistingvoltagedropsover
theresistors.
Inthefolowingfigure,acircuitwithtwobatteriescanbeobservedthatallowsus
wilallowtosolveanapplicationexample.
[Link]
Notethatourcircuithastwobatteriesandtworesistorsandwe
deseamossabercualeslatensióndecadapunto(oelpotencial),conreferenciaal
negativeterminalofB1towhichweplaceasymbolthatrepresentsa
[Link]
Earthasavastconductorofelectricity.
Thesourcetensionsaresimplythoseindicatedinthecircuit,butif
weintendtoapplythevoltagedropsacrosstheresistors,wemustdetermine
First,whatisthecurrentflowingthroughthat?Todeterminethecurrent,
First,wemustdeterminewhatthevoltageofalloursourcescombinedis.
Notethatthetwosourcesareconnectedinwaysthattheirterminals
[Link]
[Link]
referencetoground,batteryB1raisesthepotentialto10VbutbatteryB2does
Reduceto1V.Thenthesourcethatcirculatescurrentisatotalof10–1.
=9V. The electrons that circulate, for example, leaving B1 and passing through R1,
[Link]
wecangroupthenthetworesistorsandthetwosourcesjustas
indicatethefolowingfigure.
Fig.4Circuitregrouping
Isthecircuitinfigure4thesameasthecircuitinfigure3?No,this
[Link]
accordingtoOhm'slaw
I=Et/R1+R2
becausetheelectronsthatleaveR1mustnecessarilypassthroughR2and
thenitisasiftherewereatotalresistorequaltothesumoftheresistors
R1 + R2 = 1100 Ohms
Itissaidthattheresistorsareconnectedinserieswhentheyareconnectedin
insuchawaythatbotharetraversedbythesamecurrentequalto
I=(10–1)/1000+100=0.00817or8.17mA
Nowthatweknowwhatthecurrentflowingthroughthecircuitis,wecancalculate
[Link]'slaw
I=V/R
itcanbeclearedthat
V=R.I
by replacing values in this way, it can be obtained that the drop across R2 is
equalto
VR2=R2.I=100.8.17mA=817mV
VR1=R1.I=1000.8.17mA=8.17V
Thesenewlycalculatedvoltagedropvaluescanbelocatedonthe
originalcircuitinordertocalculatethedesiredvoltage.
Fig.5Solvedcircuit
Observingthefourarrowsofthesourcetensionsandthedropsof
tensioncanverifythecompliancewiththesecondlawofKirchoff,since
startingfromthereferencemassandrotatingclockwise
wecansaythatclock
10V–8.17V–1V–0.817 = 0 V
orbytransposingtermsandleavingthesourcesontherightandthe
voltagedropstotheleftwecansaythatthesumofthevoltagesof
source
And we can easily calculate that the voltage across the circuit output is
of
0,817V+1V=1,817V
withthepolarityindicatedinthecircuit,thatis,positive.