If you have an integer value, say 234 and you need to get all the values based on their decimal places.
You need to simple divide the integer say 'a', with its decimal position
(a/1 ) % 10 gives you the one's digit
(a/10) %10 gives you the ten's digit and so on.....
CODE:
module top;
int unsigned a = 234;
initial begin
$display("A_1 :%0d",(a/1)%10 );
$display("A_10 :%0d",(a/10)%10 );
$display("A_100:%0d",(a/100)%10);
end
endmodule:top
int unsigned a = 234;
initial begin
$display("A_1 :%0d",(a/1)%10 );
$display("A_10 :%0d",(a/10)%10 );
$display("A_100:%0d",(a/100)%10);
end
endmodule:top
RESULT:
A_1 :4
A_10 :3
A_100:2
A_10 :3
A_100:2
No comments:
Post a Comment