verilogquartus

Binary value representation issue in verilog


My task is to create a text file and put my first name as binary data in the text file, and then to read this file and convert this binary to characters and put it in another file as characters.

So my question is how do I represent my name in binary.

I tried:

reg [255:0] myname = 01001110011010010110101101101111011011000110111101111010;

But it did not work. The error says the number is too big.

Then I tried:

reg [1:0] myname1 = 2'b0100_1110_0110_1001_0110_1011_0110_1111_0110_1100_0110_1111_0111_1010;

This also did not work. It always gave "_" as an output.


Solution

  • reg [255:0] myname = 01001110011010010110101101101111011011000110111101111010;
    

    In this case you have a huge decimal number 1,001,110,011,010,010,110,101,101,101,111,011,011,000,110,111,101,111,010 which you try to assign to a relatively small reg (256 bit wide). It does fit in 256 bits but you will have big problems decoding it.

    reg [1:0] myname1 = 2'b0100_1110_0110_1001_0110_1011_0110_1111_0110_1100_0110_1111_0111_1010;
    

    Here you are trying to squeeze a 56 bit binary number into a 2 bit variable. This is physically impossible and the number gets truncated to 2 bits. Underscores are only used for readabilityt purposes and do not have any other effect.

    I guess, you need something like the following:

    reg [255:0] myname = 256'b01001110011010010110101101101111011011000110111101111010;
    

    You can add underscores for readability if you wish.