Continue to Site

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 to get the integer result

Status
Not open for further replies.

jkairup

Newbie level 3
Joined
Sep 30, 2015
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
30
I'm trying to make a counter to count the number of the '1' from the input data.
In the simulation part, the result is shown as a 3 bits binary. How to convert the binary to integer. Image.PNG
like in the image, the output "100" , how to use "4" instead of "100". Thank you!
Here is the code.

Code:
 library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity numb_of_1_counter is
    Port ( data : in  STD_LOGIC_VECTOR (7 downto 0);
           output : out integer range 0 to 8
			  
			  );
end numb_of_1_counter;

architecture func of numb_of_1_counter is

begin
process (data)
variable temp : integer range 0 to 8;
begin
temp := 0;
for i in 0 to 7 loop
if (data(i) = '1') then
temp := temp + 1;
end if;
end loop;
output <=  temp;

end process;
end func;



Thanks!
 

Hi,

Binary, hex or integer are just the same but the representation is different.
There is no need to transform.

You may adjust bit width ... A byte should be considered to have 8 bits.

So the binary value "010" should be "0b0000 0010"
Here the "0b" is a prefix to show it is a binary value, and the space is for better readability. 4 bits also represent a hex nibble.
The same value represented in hex is "0x02". Here "0x" is the prefix to show it is represented as hex.

Both are the same 8 data lines with each the same value.

******

Different is when you want to display the value on some kind of ASCII display.
Then there are functions (like printf) to divide the value in (independent integer values)
Hundreds: =0
Tens: = 0
And units:= 2
Then those three integer values are formed into independent 8 bit ASCII values:
0x30, 0x30, 0x32 that are displayed asa string showing "002". The function usually truncates leading zeroes to just show "2".

**
Another example:
"0b1001 0101" = "0x95" = 149.
Binary, hex, integer. In a controller, processor, PLD (8 bit wide) all three is the same..just 8 data lines.

In binary representation the values of the bits are: 128/64/31/16/8/4/2/1.
So "0b1001 0101" means 128+16+4+1 = 149

In hex the nibble values are 16/1,
So "0x95" means (9 × 16) + (5 × 1) = 144 + 5 = 149

To complete it: for decimal the values are 100/10/1.
So 149 means (1 × 100) + (4 × 10) + (9 × 1) = 149

For a digital device binary, integer and hex are usual and logical.
For a human being the decimal system is most probably used because we have ten fingers..but it is quite unusual for microcontrollers and therefore needs additional effort.

Klaus
 

Right click on the signal - select display mode as "unsigned"
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top