How to print a long unsigned ?

Discussion in 'VHDL' started by Lolo, Sep 22, 2003.

  1. Lolo

    Lolo Guest

    Dear all,

    I have a long unsigned:
    o: out unsigned (99 downto 0)
    which I want to print in decimal.

    I can use the write procedure of the std.textio package, after a conversion to
    integer:
    write(L, to_integer(o))
    But this fails when o >= 2**32.

    In std_logic_textio, write is overloaded on std_logic_vector. So
    write(L, std_logic_vector(o)) works fine but unfortunately print the
    value in binary.

    I looked at some contribution packages providing a printf-like feature. But none
    is able to handle values > 32 bits.

    Do you know of any procedure to print long unsigneds in decimal ? (Hexa would be
    okay even if not the perfect solution.)

    Thanks in advance.

    (non-spammers will remove all 'x')
    --
    Ce message a ete poste via la plateforme Web club-Internet.fr
    This message has been posted by the Web platform club-Internet.fr

    http://forums.club-internet.fr/
     
    Lolo, Sep 22, 2003
    #1
    1. Advertisements

  2. Lolo wrote:

    > Do you know of any procedure to print long unsigneds in decimal ? (Hexa would be
    > okay even if not the perfect solution.)


    Heres an unsigned to hex string function:

    http://groups.google.com/groups?q=arg_pad_left

    -- Mike Treseler
     
    Mike Treseler, Sep 22, 2003
    #2
    1. Advertisements

  3. Lolo

    VhdlCohen Guest

    >I have a long unsigned:
    > o: out unsigned (99 downto 0)
    >which I want to print in decimal.


    Use the image package at my site. I updated to use the use ieee.numeric_std
    package.
    library IEEE;
    use IEEE.Std_Logic_1164.all;
    use IEEE.Std_Logic_TextIO.all;
    use ieee.numeric_std.all;
    -- use IEEE.Std_Logic_Arith.all;

    library Std;
    use STD.TextIO.all;

    package Image_Pkg is
    function Image(In_Image : Time) return String;
    function Image(In_Image : Bit) return String;
    function Image(In_Image : Bit_Vector) return String;
    function Image(In_Image : Integer) return String;
    function Image(In_Image : Real) return String;
    function Image(In_Image : Std_uLogic) return String;
    function Image(In_Image : Std_uLogic_Vector) return String;
    function Image(In_Image : Std_Logic_Vector) return String;
    function Image(In_Image : Signed) return String;
    function Image(In_Image : UnSigned) return String;

    function HexImage(InStrg : String) return String;
    function HexImage(In_Image : Bit_Vector) return String;
    function HexImage(In_Image : Std_uLogic_Vector) return String;
    function HexImage(In_Image : Std_Logic_Vector) return String;
    function HexImage(In_Image : Signed) return String;
    function HexImage(In_Image : UnSigned) return String;

    function DecImage(In_Image : Bit_Vector) return String;
    function DecImage(In_Image : Std_uLogic_Vector) return String;
    function DecImage(In_Image : Std_Logic_Vector) return String;
    function DecImage(In_Image : Signed) return String;
    function DecImage(In_Image : UnSigned) return String;
    end Image_Pkg;

    ----------------------------------------------------------------------------
    Ben Cohen Publisher, Trainer, Consultant (310) 721-4830
    http://www.vhdlcohen.com/
    Author of following textbooks:
    * Using PSL/SUGAR with Verilog and VHDL
    Guide to Property Specification Language for ABV, 2003 isbn 0-9705394-4-4
    * Real Chip Design and Verification Using Verilog and VHDL, 2002 isbn
    0-9705394-2-8
    * Component Design by Example ", 2001 isbn 0-9705394-0-1
    * VHDL Coding Styles and Methodologies, 2nd Edition, 1999 isbn 0-7923-8474-1
    * VHDL Answers to Frequently Asked Questions, 2nd Edition, isbn 0-7923-8115
    ------------------------------------------------------------------------------
     
    VhdlCohen, Sep 22, 2003
    #3
  4. Lolo

    Jim Lewis Guest

    I have not seen any packages that handle printing bigger
    than 31/32 bits of data. Ben Cohen's above throws out bits
    above 31/32. So does the one that part of the Free Model Foundry.


    Printing Hex
    =======================
    If hex is ok, the easy way is to use std_logic_textio and do:
    hwrite(L, std_logic_vector(o));

    While std_logic_textio is not a standard, under the IEEE P1164
    it is a candidate to become a standard.

    One annoying feature of std_logic_textio is that the
    array must be sized n*4. Hence if your array is not a multiple
    of 4, you must pad it (hopefully we will get to fix this).


    Bruteforcing Decimal to work
    ===============================
    If you are using the package numeric_std, use / and mod
    to break your number into 4 pieces (use 10**9 = the largest
    power of 10 that fits into 31/32 bits). Now you can
    print by using write(L, to_integer(i), left, 9) ;


    There is a proposal to extend std_logic_textio when it
    gets standardized to have a dwrite and a dread.

    There is also a proposal to add these for bit_vector under
    the vhdl-200x-ft effort. See: http://www.eda.org/vhdl-200x/vhdl-200x-ft


    If you find anything better than what I suggested, please
    pass it along to either the working groups or to myself
    as I am helping with both of the above efforts.


    Cheers,
    Jim Lewis
    --
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Jim Lewis
    Director of Training mailto:
    SynthWorks Design Inc. http://www.SynthWorks.com
    1-503-590-4787

    Expert VHDL Training for Hardware Design and Verification
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    Lolo wrote:

    > Dear all,
    >
    > I have a long unsigned:
    > o: out unsigned (99 downto 0)
    > which I want to print in decimal.
    >
    > I can use the write procedure of the std.textio package, after a conversion to
    > integer:
    > write(L, to_integer(o))
    > But this fails when o >= 2**32.
    >
    > In std_logic_textio, write is overloaded on std_logic_vector. So
    > write(L, std_logic_vector(o)) works fine but unfortunately print the
    > value in binary.
    >
    > I looked at some contribution packages providing a printf-like feature. But none
    > is able to handle values > 32 bits.
    >
    > Do you know of any procedure to print long unsigneds in decimal ? (Hexa would be
    > okay even if not the perfect solution.)
    >
    > Thanks in advance.
    >
    > (non-spammers will remove all 'x')
     
    Jim Lewis, Sep 23, 2003
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edward Arthur

    Printing unsigned long long int's

    Edward Arthur, Nov 15, 2003, in forum: C++
    Replies:
    1
    Views:
    5,407
    Ivan Vecerina
    Nov 15, 2003
  2. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    970
    Eric Sosman
    Jul 8, 2003
  3. Replies:
    1
    Views:
    620
    Diez B. Roggisch
    Jun 1, 2005
  4. sridhar

    comparing unsigned long and unsigned int

    sridhar, Nov 1, 2004, in forum: C Programming
    Replies:
    6
    Views:
    704
    J. J. Farrell
    Nov 3, 2004
  5. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,576
    Peter Shaggy Haywood
    Sep 20, 2005
  6. CFAN
    Replies:
    6
    Views:
    1,129
    Tor Rustad
    Apr 4, 2007
  7. trbosjek

    print unsigned long long right justified

    trbosjek, Jul 3, 2007, in forum: C Programming
    Replies:
    8
    Views:
    437
    CBFalconer
    Jul 4, 2007
  8. pozz
    Replies:
    12
    Views:
    1,065
    Tim Rentsch
    Mar 20, 2011
Loading...