Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How can i provide space b/w the bits of a binary string ?

Status
Not open for further replies.

mona_c

Junior Member level 1
Joined
Jan 1, 2006
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,476
help ....Verilog

Hello every one

well i need help regarding ..Verilog formats.... can any one tell...that..how can i provide space b/w the bits of a single binary string...e.g. 11000111 is a binary no. now i need the same no. but with spaces..like this...
1 1 0 0 0 1 1 1 or vice versa

can v do it using Verilog???

today i m adding one more ques to this one.... i m not able to read data..from the text file..into my test bench ..cany one tell me how to do that in verilog?

thanx
take care
Mona
 

vvvvv

Member level 1
Joined
May 18, 2004
Messages
39
Helped
9
Reputation
18
Reaction score
0
Trophy points
1,286
Activity points
518
help ....Verilog

Create array of bytes and write to it char codes
of ones = 31h
zeros = 30h
spaces=20h
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
638
Reputation
1,274
Reaction score
89
Trophy points
1,328
Location
USA
Activity points
33,176
help ....Verilog

Please describe more clearly what type variable you are trying to manipulate. Maybe show us your code example.
 

z81203

Full Member level 5
Joined
Aug 1, 2001
Messages
308
Helped
5
Reputation
10
Reaction score
1
Trophy points
1,298
Activity points
2,356
help ....Verilog

you would be try this "1_1_0_0_0_1_1_1". normally i wrote binary like this "8'b1010_0101".
 

mona_c

Junior Member level 1
Joined
Jan 1, 2006
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,476
Re: help ....Verilog

vvvvv said:
Create array of bytes and write to it char codes
of ones = 31h
zeros = 30h
spaces=20h

can u pplzz elaborate what u wanna say

Added after 4 minutes:

echo47 said:
Please describe more clearly what type variable you are trying to manipulate. Maybe show us your code example.



no code is there....the thing is very clear..... see this no. 1100 now i want this no. to show as 1 1 0 0 ..i.e. spaces in b/w the bits of the binary no. i want to manipulate an array of this kind...now can v do this suing verilog or using matlab???
 

gliss

Advanced Member level 2
Joined
Apr 22, 2005
Messages
692
Helped
75
Reputation
150
Reaction score
16
Trophy points
1,298
Activity points
5,892
help ....Verilog

Actually, it's not very clear what you want to do.
 

mona_c

Junior Member level 1
Joined
Jan 1, 2006
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,476
Re: help ....Verilog

gliss said:
Actually, it's not very clear what you want to do.


dear...nothing is there..... see this string of binary bits ... 10101011 now i want to put spaces b/w the bits of this number so that it looks like
1 0 1 0 1 0 1 1

hope i m clear now
 

gliss

Advanced Member level 2
Joined
Apr 22, 2005
Messages
692
Helped
75
Reputation
150
Reaction score
16
Trophy points
1,298
Activity points
5,892
help ....Verilog

I'm trying to understand. You are typing this in a text editor? You are writing a Verilog module and you are entering a literal string?
-or-
You are watching the results of a simulation and see "101010011" get printed to the console or output file, and instead want to see "1 0 1 0 1 0 1 1"?
There are possibilities here. What context is the binary number in?
 

vivek

Member level 4
Joined
May 19, 2005
Messages
69
Helped
10
Reputation
20
Reaction score
1
Trophy points
1,288
Activity points
2,040
Re: help ....Verilog

Hi
if u are using $display, use '\b' to get a blank space or ' to '\t' to get a tab.

Eg : $display("%b\b%b\b%b\b%b", array[0],array[1],array[2],array[3]);

This should give you like : 1 0 1 0 instead of 1010

If you want more space use \t instead of \b

For reading from a file to your testbench consider using $fread, $fscanf, $fgetc.

Hope this helps

Vivek:D
 

mona_c

Junior Member level 1
Joined
Jan 1, 2006
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,476
Re: help ....Verilog

gliss said:
I'm trying to understand. You are typing this in a text editor? You are writing a Verilog module and you are entering a literal string?
-or-
You are watching the results of a simulation and see "101010011" get printed to the console or output file, and instead want to see "1 0 1 0 1 0 1 1"?
There are possibilities here. What context is the binary number in?

hi..

the later one is correct !!! & i need to write..this form into the text file..taking output from a verilog code
 

gliss

Advanced Member level 2
Joined
Apr 22, 2005
Messages
692
Helped
75
Reputation
150
Reaction score
16
Trophy points
1,298
Activity points
5,892
help ....Verilog

If it's the later one, then I think vivek has answered your question.
 

vivek

Member level 4
Joined
May 19, 2005
Messages
69
Helped
10
Reputation
20
Reaction score
1
Trophy points
1,288
Activity points
2,040
Re: help ....Verilog

mona_c said:
the later one is correct !!! & i need to write..this form into the text file..taking output from a verilog code

Hi
If u want to write this info into a file use $fdisplay. You should open a file for this like :
Code:
   reg [0:3] array;
   integer log_pointer;
   initial
     log_pointer = $fopen("file_name");
     $fdisplay (log_pointer,"data = %b\b%b\b%b\b%b", array[0],array[1],
                   array[2],array[3]);
   end
This will write your data to a file of the name you specify. log_pointer shall be the file pointer for the file you opened. It will increment automatically by one line for every $fdisplay.
If you need more such info about verilog HDL you can refer the book "Verilog HDL: A Guide to Digital Design and Synthesis" by Samir Palnitkar. The ebook is available in this forum. Pretty good for beginning with verilog.

Hope this helps
Vivek:D
 

mona_c

Junior Member level 1
Joined
Jan 1, 2006
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,476
Re: help ....Verilog

vivek said:
mona_c said:
the later one is correct !!! & i need to write..this form into the text file..taking output from a verilog code

Hi
If u want to write this info into a file use $fdisplay. You should open a file for this like :
Code:
   reg [0:3] array;
   integer log_pointer;
   initial
     log_pointer = $fopen("file_name");
     $fdisplay (log_pointer,"data = %b\b%b\b%b\b%b", array[0],array[1],
                   array[2],array[3]);
   end
This will write your data to a file of the name you specify. log_pointer shall be the file pointer for the file you opened. It will increment automatically by one line for every $fdisplay.
If you need more such info about verilog HDL you can refer the book "Verilog HDL: A Guide to Digital Design and Synthesis" by Samir Palnitkar. The ebook is available in this forum. Pretty good for beginning with verilog.

Hope this helps
Vivek:D

Hi vivek

thanx for ur help..but dear..i m not getting the right result yet..see what i m getting when i applied ur code

data = xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b
data = xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b
data = xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b
data = xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b
data = xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b
data = xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b
data = xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b
data = xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b xbxbxbx b

certainly not a desirable thing :cry:
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
638
Reputation
1,274
Reaction score
89
Trophy points
1,328
Location
USA
Activity points
33,176
Re: help ....Verilog

If that's approximately what you want, then how about changing the $fdisplay statement slightly?

Code:
integer log_pointer, n;
initial begin
  log_pointer = $fopen("file_name");
  for (n=0; n<16; n=n+1)
    $fdisplay (log_pointer,"data = %b %b %b %b", n[3], n[2], n[1], n[0]);
  $fclose(log_pointer);
end
Code:
data = 0 0 0 0
data = 0 0 0 1
data = 0 0 1 0
data = 0 0 1 1
data = 0 1 0 0
data = 0 1 0 1
data = 0 1 1 0
data = 0 1 1 1
data = 1 0 0 0
data = 1 0 0 1
data = 1 0 1 0
data = 1 0 1 1
data = 1 1 0 0
data = 1 1 0 1
data = 1 1 1 0
data = 1 1 1 1
 

    mona_c

    Points: 2
    Helpful Answer Positive Rating

mona_c

Junior Member level 1
Joined
Jan 1, 2006
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,476
Re: help ....Verilog

echo47 said:
If that's approximately what you want, then how about changing the $fdisplay statement slightly?

integer log_pointer, n;
initial begin
log_pointer = $fopen("file_name");
for (n=0; n<16; n=n+1)
$fdisplay (log_pointer,"data = %b %b %b %b", n[3], n[2], n[1], n[0]);
$fclose(log_pointer);
end[/code]
Code:
data = 0 0 0 0
data = 0 0 0 1
data = 0 0 1 0
data = 0 0 1 1
data = 0 1 0 0
data = 0 1 0 1
data = 0 1 1 0
data = 0 1 1 1
data = 1 0 0 0
data = 1 0 0 1
data = 1 0 1 0
data = 1 0 1 1
data = 1 1 0 0
data = 1 1 0 1
data = 1 1 1 0
data = 1 1 1 1

Hi echo47

well i have done my task...with the help of ur two codes....the things is choose the mid way of two :D yepp
that is how i did & all thanx to u 8)
here is the code

Code:
integer log_pointer;
wire [31:0] out;
initial begin
  log_pointer = $fopen("format.txt");
   	
		$monitor($realtime,,"ps %d %h %h %h %d ",in,clk,oe,reset,out);
  $fdisplay (log_pointer,"%b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b", out[31], out[30], out[29], out[28], out[27], out[26], out[25], out[24], out[23], out[22], out[21], out[20], out[19], out[18], out[17], out[16], out[15], out[14], out[13], out[12], out[11], out[10], out[9], out[8], out[7], out[6], out[5], out[4], out[3], out[2], out[1], out[0]);
 $fclose(log_pointer);
	$finish;
 end

& i got the correct ans..thanx again ..

God Bless u
take care
bye for now
Mona
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top