ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [SystemVerilog] 데이터 타입 5 string
    개발/SystemVerilog 2022. 1. 17. 19:03

    검증을 위해서 문자열 타입을 제공한다.

     

    string str1 = "hello world!";

    스트링은 "" 사이에 값을 넣어서 할당한다. 개행문자는 포함되지 않는다.

     

    https://www.chipverify.com/systemverilog/systemverilog-strings

    문자열 타입의 연산자를 지원한다.

    문자열의 비교는 각 문자의 아스키 코드값을 기준으로 비교한다.

     

    string str1 = "aaa";
    string str2 = "aaab";
    
    // str2 > str1
    $display("%d ", str1 < str2);

    위와 같은경우, str1이 str2 안에 포함이 되면, 길이가 긴 쪽이 더 크다.

     

     

     

    문자열의 메서드 정리

         
    str.len() function int len() Returns the number of characters in the string
    str.putc() function void putc (int i, byte c); Replaces the ith character in the string with the given character
    str.getc() function byte getc (int i); Returns the ASCII code of the ith character in str
    str.tolower() function string tolower(); Returns a string with characters in str converted to lowercase
    str.compare(s) function int compare (string s); Compares str and s, as in the ANSI C stcmp function
    str.icompare(s) function int icompare (string s); Compares str and s, like the ANSI C strcmp function
    str.substr (i, j) function string substr (int i, int j); Returns a new string that is a substring formed by characters in position i through j of str

     

         
    str.atoi() function integer atoi(); Returns the integer corresponding to the ASCII decimal representation in str
    str.atohex() function integer atohex(); Interprets the string as hexadecimal
    str.atooct() function integer atooct(); Interprets the string as octal
    str.atobin() function integer atobin(); Interprets the string as binary
    str.atoreal() function real atoreal(); Returns the real number corresponding to the ASCII decimal representation in str
    str.itoa(i) function void itoa (integer i); Stores the ASCII decimal representation of i into str
    str.hextoa(i) function void hextoa (integer i); Stores the ASCII hexadecimal representation of i into str
    str.octtoa(i) function void octtoa (integer i); Stores the ASCII octal representation of i into str
    str.bintoa(i) function void bintoa (integer i); Stores the ASCII binary representation of i into str
    str.realtoa(r) function void realtoa (real r); Stores the ASCII real representation of r into str

    https://www.chipverify.com/systemverilog/systemverilog-strings

     

     

     

    '개발 > SystemVerilog' 카테고리의 다른 글

    [SystemVerilog] 클래스 3 상속  (0) 2022.01.24
    [SystemVerilog] 클래스 1  (0) 2022.01.17
    [SystemVerilog] 인터페이스 2  (0) 2022.01.16
    [SystemVerilog] 인터페이스 1  (0) 2022.01.16
    [SystemVerilog] packed / unpacked array  (0) 2022.01.15
Designed by Tistory.