Problem 2. Consider a light system that is controlled by an 8-bit register, whic
ID: 2267821 • Letter: P
Question
Problem 2. Consider a light system that is controlled by an 8-bit register, which carries a command to the light system. We call this register Light System Command or LSC. Here are the specifications of this register: . Bit 0-1 control the light intensity: 00 off, 01 low, 10 medium, 11 high. Bit 2-4 control the color: blue 000, green 001, red 010, yellow 011, white 100. Example: If we assign OxC3 to LSC, the light system will interpret it as "It should turn on lamp number # 6 with highest intensity in blue color."Explanation / Answer
since any programming language is not particularly mentioned, I used C language to write the code. Although the logic is same for all the languages.
The code is given below
#define off=0;
#define low=1;
#define medium=2;
#define high=3;
#define blue=0;
#define green=1;
#define red =2;
#define yellow=3;
#define white=4;
makeLSC(int lampnumber,int color,int intensity)
{
int hex;
hex=intensity|color<<2|lampnumber<<5; //read as inesity OR color left shift 2 OR lampnumber left shift 5
return (hex);//we shift the digits and use simple 'OR' to join them
//we get integer value corresponding to the hex and we can get the hex code by conversion to hexa decimal
}
main()
{
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.