Question

Design and implement a 8 or 6 Port Dip Switch that control 4 LED Lights Components: Dip Switch, L...

Design and implement a 8 or 6 Port Dip Switch that control 4 LED Lights Components: Dip Switch, LEDs, Resistors Description: Using a dipswitch create an application that uses bitwise operator to shift the bits to the left one bit at a time. Turning on one LED at a time that corresponds to the dipswitch position. After the bits are shifted 4 positions, start shifting the bits to the right turning the light on and off in the reverse order Example: 1 = 0001

0 0
Add a comment Improve this question Transcribed image text
Answer #1

For this LED operation using DIP switch you first go through below concepts. Then use If and else condition as per Microcontroller / Microprocessor you are using ,convert same into hex file burn into processor and then connect necessary hardware as per assigned input output terminals of DIP switch.

Explanation of concept:-

Shift and Logical Operators

A shift operator performs bit manipulation on data by shifting the bits of its first operand right or left. The next table summarizes the shift operators available in the Java programming language.

Shift Operators

Operator

Use

Description

<<

op1 << op2

Shift bits of op1 left by distance op2; fills with zero bits on the right-hand side

>>

op1 >> op2

Shift bits of op1 right by distance op2; fills with highest (sign) bit on the left-hand side

>>>

op1 >>> op2

Shift bits of op1 right by distance op2; fills with zero bits on the left-hand side

Each operator shifts the bits of the first operand over by the number of positions indicated by the second operand. The shift occurs in the direction indicated by the operator itself. For example, the following statement shifts the bits of the integer 13 to the right by one position:

13 >> 1;

The binary representation of the number 13 is 1101. The result of the shift operation is 1101 shifted to the right by one position — 110, or 6 in decimal. The left-hand bits are filled with 0s as needed.

The following table shows the four operators the Java programming language provides to perform bitwise functions on their operands:

Logical Operators

Operator

Use

Operation

&

op1 & op2

Bitwise AND if both operands are numbers;
conditional AND if both operands are boolean

|

op1 | op2

Bitwise OR if both operands are numbers;
conditional OR if both operands are boolean

^

op1 ^ op2

Bitwise exclusive OR (XOR)

~

~op2

Bitwise complement

When its operands are numbers, the & operation performs the bitwise AND function on each parallel pair of bits in each operand. The AND function sets the resulting bit to 1 if the corresponding bit in both operands is 1, as shown in the following table.

The Bitwise AND Function

Bit in op1

Corresponding Bit in op2

Result

0

0

0

0

1

0

1

0

0

1

1

1

Suppose that you were to AND the values 13 and 12, like this: 13 & 12. The result of this operation is 12 because the binary representation of 12 is 1100, and the binary representation of 13 is 1101.

    1101     //13

& 1100     //12

------

    1100     //12

If both operand bits are 1, the AND function sets the resulting bit to 1; otherwise, the resulting bit is 0. So, when you line up the two operands and perform the AND function, you can see that the two high-order bits (the two bits farthest to the left of each number) of each operand are 1. Thus, the resulting bit in the result is also 1. The low-order bits evaluate to 0 because either one or both bits in the operands are 0.

When both of its operands are numbers, the | operator performs the inclusive or operation, and ^ performs the exclusive or (XOR) operation. Inclusive or means that if either of the two bits is 1, the result is 1. The following table shows the results of an inclusive or operation.

The Bitwise Inclusive OR Function

Bit in op1

Corresponding Bit in op2

Result

0

0

0

0

1

1

1

0

1

1

1

1

Exclusive or means that if the two operand bits are different the result is 1; otherwise the result is 0. The following table shows the results of an exclusive or operation.

The Bitwise Exclusive OR (XOR) Function

Bit in op1

Corresponding Bit in op2

Result

0

0

0

0

1

1

1

0

1

1

1

0

And finally, the complement operator (~) inverts the value of each bit of the operand: If the operand bit is 1, the result is 0; if the operand bit is 0, the result is 1. For example, ~1011 (11) is 0100(4).

Among other things, bitwise manipulations are useful for managing sets of boolean flags. Suppose, for example, that your program had several boolean flags that indicated the state of various components in your program: is it visible, is it draggable, and so on. Rather than define a separate boolean variable to hold each flag, you could define a single variable, flags, for all of them. Each bit within flags would represent the current state of one of the flags. You would then use bit manipulations to set and to get each flag.

Add a comment
Know the answer?
Add Answer to:
Design and implement a 8 or 6 Port Dip Switch that control 4 LED Lights Components: Dip Switch, L...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design and implement a 8 or 6 Port Dip Switch that control 4 LED Lights Components:...

    Design and implement a 8 or 6 Port Dip Switch that control 4 LED Lights Components: Dip Switch, LEDs, Resistors Description: Using a dipswitch create an application that uses bitwise operator to shift the bits to the left one bit at a time. Turning on one LED at a time that corresponds to the dipswitch position. After the bits are shifted 4 positions, start shifting the bits to the right turning the light on and off in the reverse order...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT