Home > Community > Forums > Functional Verification > convert string to list of bit

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 convert string to list of bit 

Last post Wed, Jul 3 2013 3:02 PM by mmbr. 2 replies.
Started by mmbr 03 Jun 2013 03:23 PM. Topic has 2 replies and 931 views
Page 1 of 1 (3 items)
Sort Posts:
  • Mon, Jun 3 2013 3:23 PM

    • mmbr
    • Not Ranked
    • Joined on Sun, Aug 2 2009
    • Posts 2
    • Points 25
    convert string to list of bit Reply

    I'm looking for a way to read a file containing (HEX) numbers.

    For each file I read, the width of the data is different (can be more than 32/64/128 bits).

    So I'm looking for a way to convert the string I read from the file to a list of bit variable.

    In order to make it easy, let say I know the size of the bits list (the data width) in advance.

    Any ideas?

    • Post Points: 20
  • Wed, Jul 3 2013 6:19 AM

    • muffi
    • Top 500 Contributor
    • Joined on Tue, Aug 4 2009
    • Bangalore, Karnataka
    • Posts 22
    • Points 305
    Re: convert string to list of bit Reply

     <'
    extend sys{
      run() is also{
        var m_file: file;
        var list1: list of uint;
        if files.file_is_readable("text.txt"){
          m_file = files.open("text.txt", "r", "Text File");
          var m_string: string;
          while files.read(m_file, m_string) {
            list1.add(append("0x", m_string).as_a(int));
          };
          print list1 using hex;
          files.close(m_file);
          };
        };
    };
    '>

    text.txt

    ======

    234d
    134d
    254d
    034d
    234a
    294b
    844a
    234d

    • Post Points: 20
  • Wed, Jul 3 2013 3:02 PM

    • mmbr
    • Not Ranked
    • Joined on Sun, Aug 2 2009
    • Posts 2
    • Points 25
    Re: convert string to list of bit Reply

    muffi Hi,

    In your example list1 is a list of uint.

    I'm looking for a solution where list1 is a list of bit.

    Lets take for example a file containg a line with the number f3.

    var lob : list of bit;

    var lob_size : uint = 5;

    After the convertion function I would like to get lob with this list:

    Specman> p lob using dec
      lob =  (5 items, dec):
                                                    1  0 0 1 1      .0

    Specman> p lob using hex
      lob =  (5 items, hex):
                                                    1  0 0 1 1      .0
     

    • Post Points: 5
Page 1 of 1 (3 items)
Sort Posts:
Started by mmbr at 03 Jun 2013 03:23 PM. Topic has 2 replies.