Posts

Showing posts from August, 2021

traffic light verilog

         module fsm(     input clk,rst,          output reg red1,green1,yellow1,red2,green2,yellow2,red3,green3,yellow3,red4,green4,yellow4     );     reg [1:0]state,next_state;     parameter s0=2'b00,s1=2'b01,s2=2'b10,s3=2'b11;     always@(posedge clk,posedge rst)     begin     if(rst) state<=s0;     else state<=next_state;     end     always@(state)     begin     case(state)     s0:next_state<=s1;     s1:next_state<=s2;     s2:next_state<=s3;     s3:next_state<=s1;     endcase      end          always@(state)     begin     case(state)     s0:{red1,green1,yellow1,red2,green2,yellow2,red3,green3,yellow3,red4,green4,yellow4}<=12'b100100010001;     s1:{red1,green1,yellow1,r...

0x12345678->0x12563478

 // Online C++ compiler to run C++ program online #include <iostream> //#include <bitset> using namespace std; int main() {    int n=0x12345678;    //bitset<32> y(n);    printf("%x",n);    cout<<endl;    //cout<<y<<endl;        int mask1=0x00ff0000;    int num1=mask1&n;    printf("%x",num1);    cout<<endl;            int mask2=0x0000ff00;    int num2=mask2&n;    printf("%x",num2);    cout<<endl;            int mask3=0x000000ff;    int num3=mask3&n;    printf("%x",num3);    cout<<endl;            int mask4=0xff000000;    int num4=mask4&n;    printf("%x",num4);    cout<<endl;        num1=num1/256;    num2...

MIN XOR

  Min XOR value Medium 61 0 Add to favorites Asked In: BOOKING.COM Given an integer array A of N integers, find the pair of integers in the array which have minimum XOR value. Report the minimum XOR value. Input Format: First and only argument of input contains an integer array A Output Format: return a single integer denoting minimum xor value Constraints: 2 <= N <= 100 000 0 <= A[i] <= 1 000 000 000 For Examples : Example Input 1: A = [0, 2, 5, 7] Example Output 1: 2 Explanation: 0 xor 2 = 2 Example Input 2: A = [0, 4, 7, 9] Example Output 2: 3 Note: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout  Sample Codes  for more details. #include   < algorithm > int  Solution::findMinXor(vector< int > &A) {      int  min=INT...

Number PAlindorme

// Online C++ compiler to run C++ program online #include <iostream> using namespace std; int rev(int n){     int ans=0;     while(n){         ans=ans*10+(n%10);         n/=10;     }     return ans; } int main() {     int n;     cin>>n;     int a=rev(n);     cout<<a<<endl;     if (n==a){         cout<<"Palindrome";              }     else{         cout<<"Not Palindrome";     }               return 0; }

setBit

 #include <iostream> using namespace std; int setBit(int n){     int count=0;     while(n/2!=0){         if(n%2==1){             count=count+1;         }         n=n/2;              }     if(n==1){         count=count+1;     }     return count; } int main() {     cout<<setBit(3);     return 0; }