Question

In: Computer Science

write a c code to test the 3rd and 8th bit set or not (1 or...

write a c code to test the 3rd and 8th bit set or not (1 or 0).
if both set, display "true";
if either one set, display "half true";
if neither set, display "false".

Solutions

Expert Solution

//Always remember bit order starts from 0.

#include <stdio.h>

int main()
{
    int num, n, bitStatus,bitStatus1; //integer declaration

    /* Input number from user */
    printf("Enter any number: ");
    scanf("%d", &num);

    /* Right shift num,3 times and perform bitwise AND with 1 */
    bitStatus = (num >> 3) & 1;
      /* Right shift num,8 times and perform bitwise AND with 1 */
     bitStatus1 = (num >> 8) & 1;
if(bitStatus==1 && bitStatus1==1){
    printf("true");
}

else if(bitStatus==1 || bitStatus1==1){
    printf("half true");
}
else{printf("false");
}
    return 0;

}



Related Solutions

Write an assembly language program code to clear and set bit 7th and 19th in a...
Write an assembly language program code to clear and set bit 7th and 19th in a 32-bit variable called N.
Write in verilog, code to implement a 6 bit multiplier. Cascade a 1 bit multiplier to...
Write in verilog, code to implement a 6 bit multiplier. Cascade a 1 bit multiplier to implement this.
code an 8 bit LFSR random number generator in system verilog. Write a test bench, load...
code an 8 bit LFSR random number generator in system verilog. Write a test bench, load the seed 11111111, and generate the first 10 random numbers.
Write a VHDL code for a 8x8 bit multiplier. use structural approach. write the design code...
Write a VHDL code for a 8x8 bit multiplier. use structural approach. write the design code and testbench. Use for-generate if possible
Write a Verilog code to implement 16 bit LFSR
Write a Verilog code to implement 16 bit LFSR
use Simpson's 3/8th Rule on the first 3 segments, and multiple application of Simpson's 1/3rd Rule...
use Simpson's 3/8th Rule on the first 3 segments, and multiple application of Simpson's 1/3rd Rule on the rest of the segments. ?(?)=400?5−900?4+675?3−200?2+25?+0.2 a = 0.12 b = 1.56 n = 7
Code in C++ please You are going to write a program for Computer test which will...
Code in C++ please You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly and provide the test to the user. When the user done the program must give the user his final score
Design a 4-bit multiplier by using 4 bit full adder and write a verilog code.
Design a 4-bit multiplier by using 4 bit full adder and write a verilog code.
1. Design a combinational circuit that coverts a 4-bit Gray code to a 4-bit Excess-3 code....
1. Design a combinational circuit that coverts a 4-bit Gray code to a 4-bit Excess-3 code. Provide detailed solution and explanation. 2. Design a double edge-triggered D flip-flop using multiplexers only. The output of the flip-flop Q should “sample” the value of the input D on both rising (+ve) and falling (-ve) edges of the clock CLK. Provide detailed solution and explanation. 3. Design an FSM counter that counts the sequence: 00, 11, 01, 10, 00, 11, ... . Provide...
write the code for 16-bit ALU using vivado. Approach : A hierarchical design approach for 16-bit...
write the code for 16-bit ALU using vivado. Approach : A hierarchical design approach for 16-bit ALU using a Full Adders (16-bit), Multiplier (16-bit), Full Subtractor (16-bit), and shift left A register. include test bench. S0 S1 Alu-operation 0 0 addition 0 1 subtraction 1 0 multiplication 1 1 shift right
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT