我有一个带有文本的列,按ASCII排序,应按以下顺序排序:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity mem_control is
port(
clk : in std_logic;
write_en : in std_logic;
read_en : in std_logic;
bus_address : in std_logic_vector(11 downto 0);
bus_data : inout std_logic_vector(31 downto 0);
write_en_sram : out std_logic;
read_en_led : out std_logic;
write_en_led : out std_logic;
write_en_scratch : out std_logic;
bus_in_sram : in std_logic_vector(31 downto 0);
bus_out_sram : out std_logic_vector(31 downto 0);
bus_in_led : in std_logic_vector(31 downto 0);
bus_out_led : out std_logic_vector(31 downto 0);
bus_in_scratch : in std_logic_vector(31 downto 0);
bus_out_scratch : out std_logic_vector(31 downto 0);
addr_out : out std_logic_vector(11 downto 0)
);
end mem_control;
architecture bhv of mem_control is
--buffer signals
signal bus_out : std_logic_vector(31 downto 0) := (others => '0');
--processes begin
begin
mem_write : process(clk) is
begin
if rising_edge(clk) then
if write_en = '1' and read_en ='0' then --writing logic
case To_integer(unsigned(bus_address)) is
when 16#000# to 16#3FF# =>
write_en_sram <= '1';
write_en_led <= '0';
write_en_scratch <= '0';
bus_out_sram <= bus_data;
addr_out <= bus_address;
when 16#400# =>
write_en_sram <= '0';
write_en_led <= '1';
write_en_scratch <= '0';
bus_out_led <= bus_data;
when 16#404# =>
write_en_sram <= '0';
write_en_led <= '0';
write_en_scratch <= '1';
bus_out_scratch <= bus_data;
when others =>
null;
end case;
end if;
end if;
end process mem_write;
mem_read : process(clk) is
begin
if rising_edge(clk) then
if read_en = '1' and write_en = '0' then --reading logic
case To_integer(unsigned(bus_address)) is
when 16#000# to 16#3FF# =>
bus_out <= bus_in_sram;
read_en_led <= '0';
addr_out <= bus_address;
when 16#400# =>
bus_out <= bus_in_led;
read_en_led <= '1';
when 16#404# =>
bus_out <= bus_in_scratch;
read_en_led <= '0';
when others =>
null;
end case;
end if;
end if;
end process mem_read;
--led register and tristate buffers
bus_data <= bus_out when(write_en = '0' and read_en = '1') else (others => 'Z');
end bhv;
然而,它被命令为:
- (hyphen)
0
1 (numbers)
2
A (uppercase)
B
_ (underscore)
a
b (lowercase)
c
如何按ASCII值进行排序?
答案 0 :(得分:4)
您可以使用ASCII:
SELECT *
FROM tab
ORDER BY ASCII(col_name) ASC
答案 1 :(得分:4)
排序顺序由排序规则控制。您可以使用BINARY排序规则按原始字节排序,在ASCII数据的情况下,它将使其按ASCII值排序。见https://dev.mysql.com/doc/refman/5.7/en/sorting-rows.html
SELECT ...
FROM mytable
ORDER BY BINARY mycolumn
这比使用ASCII()
函数更灵活,因为该函数只返回第一个字符的ASCII值。使用BINARY排序规则允许按完整字符串排序。