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.

[SOLVED] logic : give value in which require decimal number represent

Status
Not open for further replies.

tayyab786

Junior Member level 3
Joined
Mar 11, 2017
Messages
28
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
224
hi all
i need a logic that give me value in which require decimal number represent

e.g 1: if input is 32 it give me value 5 as 32 represent in 5 bit
2 if input is 42 it give me value 5 as 42 represent in 5 bit
3 if input is 128 it give me a value 7 as 128 represent in 7 bit and so on
 

Hi,

you need to give more information:
* what langauge
* on what hardware
* how is the decimal input made (as ASCII string?)
* what range is the decimal input (integer values only?)

Klaus
 

Hi,

you need to give more information:
* what langauge
* on what hardware
* how is the decimal input made (as ASCII string?)
* what range is the decimal input (integer values only?)

Klaus

language is verilog
hardware is fpga
decimal value is integer value
the input is in decimal value ( for hardware i know its in binary format but for simulation its decimal value ) its does't matter
range depend on user but not exceed with maximum value e.g max value is 255 so user have option to enter either 10,20 and so on the ans or output should be 4,5 respectively
 
Last edited:

And what problems are you having doing it yourself?
 

Hi,

the input is in decimal value
There is no decimal input to an FPGA. Either there are ten lines per digit, or BCD, or the input is not dcimal, but binary.

for hardware i know its in binary format but for simulation its decimal value
Maybe it´s straight binary, but the "input" or "display" in the simulator is "decimal".

its does't matter
You urgently need to know this, else it is impossible to write code.

***
For an 8 bit binary value (uint8)
My solution is to use a counter "n" which counts 8 down to 0
on each run check the "n-1"-th bit of the input
If the value of the bit is "1", then out put n as result and stop forther runs.

Example: (pseudo code)
Decimal "36" --> binary "0010 0100"
(it contains 8 bits. bit 0 = LSB with value "1", bit 7 = MSB with value "128")
init counter = 8
test bit (8-1) = test bit 7 = test MSB ("0010 0100")
it is not "1"
next run
counter = 7
test bit (7-1) = test bit 6 ("0010 0100")
it is not "1"
next run
counter = 6
test bit (6-1) = test bit 5 ("0010 0100")
it is "1"
Match! --> output counter value (in this case "6")
finish

Klaus
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top