Check for PALINDROME of a String using SV

 CODE:

module tb;

  string s1 = "madam";
  string s2;
  initial
    begin
      s2 = {<<8{s1}}; //Storing each character as 8-bits using Streaming Op.
      if(s1 == s2) 
        $display("\n %s is a Palindrome \n", s1);
      else 
        $display("\n %s is NOT a Palindrome \n", s1);
    end
endmodule


SAMPLE OUTPUT:


With Different String match:

module tb;

  string s1 = "jolly";

  string s2;

  initial

    begin

      s2 = {<<8{s1}}; //Storing each character as 8-bits

      $display("\nReversal of gn. string is: %s",s2);

      if(s1 == s2) 

        $display("%s is a Palindrome \n", s1);

      else 

        $display("(Given String)%s != %s(Reversed String)",s1,s2);

      $display("Therefore, %s is NOT a Palindrome \n", s1);

    end

endmodule


 SAMPLE OUTPUT:





You can buy me a coffee!
https://www.buymeacoffee.com/chilllearn








Comments

Popular posts from this blog

Constraint to generate 100 phone numbers, where the first three digits should be '982'

System Verilog Constraint Scenario: 2