I'm here to consult with you all. i wanna ask which tool is best to convert decimal to ascii. I'm also searching on it. Give your suggestion. if i would find a suitable tool, i will also share with you.
Be sure to click 'more' and select 'suggest as answer'!
If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!
I'm here to consult with you all. i wanna ask which tool is best to convert decimal to ascii. I'm also searching on it. Give your suggestion. if i would find a suitable tool, i will also share with you.
If you use C, it's as simple as storing the decimal number into a uint8_t and then printing it out as a char.
Some calculators can do it ... there are also websites that will do the same with a quick Google search although I will refrain from recommending any particular one to avoid being flagged as spam.
- Gough
Here's a code snippet in VHDL, I doubt that it's quite what you are after (it converts binary to ascii) but it gives an idea of the range of valid answers.
Is it the best tool - of course not, but it's good where it's used.
when PAR_READ => reg_rd <= '1'; pars_state <= PAR_READ_1; when PAR_READ_1 => if reg_trf_done = '1' then v_reg := unsigned(reg_in); if (v_reg(31) = '1') and ((cmnd_char = x"6a") -- reg a is 32 bit signed so deal with -ve case or (cmnd_char = x"67") -- reg g is interleave accumulator or (cmnd_char = x"71") -- reg q is pos_count1 or (cmnd_char = x"72") -- reg r is pos_count2 or (cmnd_char = x"73") -- reg s is pos_count3 ) then v_reg(31) := '0'; v_reg(30 downto 0) := ((not v_reg(30 downto 0)) + "0000000000000000000000000000001"); isneg <= '1'; tx_char <= "00101101"; -- negative sign tx_wrreq <= '1'; -- send it out else isneg <= '0'; end if; reg_val <= v_reg; reg_rd <= '0'; ten_pwrs_index <= "1001"; -- points to 1e9 digit <= "0000"; nz_sent <= '0'; -- used to prevent leading zeros, set when a character is sent pars_state <= PAR_READ_1A; end if; when PAR_READ_1A => tx_wrreq <= '0'; -- must be cleared after -ve so clear anyway is safe pars_state <= PAR_READ_2; when PAR_READ_2 => if reg_val >= ten_pwrs(to_integer(ten_pwrs_index)) then reg_val <= reg_val - ten_pwrs(to_integer(ten_pwrs_index)); digit <= digit + 1; else if (digit > 0) or (nz_sent = '1') or (ten_pwrs_index = 0) then tx_char <= std_logic_vector(("0000" & digit) + 48); tx_wrreq <= '1'; nz_sent <= '1'; pars_state <= PAR_READ_3; end if; ten_pwrs_index <= ten_pwrs_index - 1; -- when ls digit will wrap to 15 end if; when PAR_READ_3 => tx_wrreq <= '0'; if ten_pwrs_index < 10 then -- traps the end condition digit <= "0000"; pars_state <= PAR_READ_2; else pars_state <= PAR_SEND_CRLF; end if; when PAR_SEND_CRLF => tx_char <= "00001101"; -- CR tx_wrreq <= '1'; pars_state <= PAR_CRLF_1; when PAR_CRLF_1 => tx_char <= "00001010"; -- LF tx_wrreq <= '1'; pars_state <= PAR_CRLF_2; when PAR_CRLF_2 => tx_wrreq <= '0'; busy <= '0'; pars_state <= PAR_IDLE;
So, first of all what do you mean by decimal - this is what I call decimal 4567 - a number represented by tokens for values 0 - 9, but I suspect you mean a numeric value in some code that you want to output as ASCII characters.
If you define the problem better it will be possible to give some answers.
MK
What is your application for the software tool? Embedded in program or stand alone?