c语言程序将正整数转换成8421码(又称BCD码)形式的字符串?怎么理解程序求注释

c语言程序将正整数转换成8421码(又称BCD码)形式的字符串?怎么理解程序求注释,第1张

c语言程序将正整数转换成8421码(又称BCD码)形式的字符串?怎么理解程序求注释

```c

#include

int main()

{

int num//定义一个变量num,用来存储需要转换的正整数

printf("请输入一个正整数:") //提示用户输入需要转换的正整数

scanf("%d",

已知字母A的ASCII码是01000001,则英文字母E的ASCII码是01000101。

ASCII码表中,大写英文字母是连续表。所以E在A后面第4位,所以E的ASCII码=01000001(二进制)+4(十进制)=01000101(二进制)。

后三位001变成101是因为这是二进制的运算,逢2进1。

ASCII码使用指定的7位或8位二进制数组合来表示128 或256 种可能的字符。标准ASCII码也叫基础ASCII码,使用7位二进制数来表示所有的大写和小写字母,数字0到9、标点符号,以及在美式英语中使用的特殊控制字符。

0~31及127(共33个)是控制字符或通信专用字符,它们并没有特定的图形显示,但会依不同的应用程序,而对文本显示有不同的影响。32~126(共95个)是字符,其中48~57为0到9的阿拉伯数字。

65~90为26个大写英文字母,97~122号为26个小写英文字母,其余为一些标点符号和运算符号等。

扩展资料:

大写英文字母ASCII码列表:

65:大写字母A

66:大写字母B

67:大写字母C

68:大写字母D

69:大写字母E

70:大写字母F

71:大写字母G

72:大写字母H

73:大写字母I

74:大写字母J

75:大写字母K

76:大写字母L

77:大写字母M

78:大写字母N

79:大写字母O

80:大写字母P

81:大写字母Q

82:大写字母R

83:大写字母S

84:大写字母T

85:大写字母U

86:大写字母V

87:大写字母W

88:大写字母X

89:大写字母Y

90:大写字母Z

参考资料来源:百度百科-ASCII

1、freq: IN INTEGER --控制输出波形的频率

输入可以定义成integer吗?我觉的不行。

2、Qout : OUT integer

输出可以定义为integer吗?不知是如何输出的

3、 COMPONENT lpm_rom0

END COMPONENT

这句什么意思,多余的吧,此处定义元件是什么意思?

4、这段程序,逻辑上有问题,乱。

在此我给你一段三角波的程序:

entity sanjiao is

Port(rst : in std_logic

clk : in std_logic

q : out std_logic_vector(7 downto 0))

end sanjiao

architecture Behavioral of sanjiao is

begin

process(clk,rst)

variable num : std_logic_vector(7 downto 0)

variable ff :std_logic:='0'

begin

if(rst='1')then

num:="00000000"

elsif(clk'event and clk='1')then

if(ff='0')then

if(num="11111110")then

num:="11111111"

ff:='1'

else

num:=num+1

end if

elsif(ff='1')then

if(num="00000001")then

num:="00000000"

ff:='0'

else

num:=num-1

end if

end if

end if

q<=num

end process

end Behavioral

正弦波的程序:

entity sins is

Port ( clk : in std_logic

rst : in std_logic

q : out std_logic_vector(7 downto 0))

end sins

architecture Behavioral of sins is

signal a : std_logic_vector(7 downto 0)

signal b : std_logic_vector(7 downto 0)

begin

process(rst,clk)

begin

if(rst='1')then

a<=(others=>'0')

elsif(clk'event and clk='1')then

if (a="10110011") then

a<= "00000000"

else

a<=a+1

end if

end if

end process

process(a)

begin

case a is

when "00000000"=>b<="00000000"

when "00000001"=>b<="00000100"

when "00000010"=>b<="00001001"

when "00000011"=>b<="00001101"

when "00000100"=>b<="00010001"

when "00000101"=>b<="00010110"

when "00000110"=>b<="00011011"

when "00000111"=>b<="00011111"

when "00001000"=>b<="00100011"

when "00001001"=>b<="00101000"

when "00001010"=>b<="00101100"

when "00001011"=>b<="00110001"

when "00001100"=>b<="00110101"

when "00001101"=>b<="00111001"

when "00001110"=>b<="00111110"

when "00001111"=>b<="01000001"

when "00010000"=>b<="01000110"

when "00010001"=>b<="01001011"

when "00010010"=>b<="01001111"

when "00010011"=>b<="01010011"

when "00010100"=>b<="01010111"

when "00010101"=>b<="01011011"

when "00010110"=>b<="01100000"

when "00010111"=>b<="01100100"

when "00011000"=>b<="01101000"

when "00011001"=>b<="01101100"

when "00011010"=>b<="01110000"

when "00011011"=>b<="01110100"

when "00011100"=>b<="01111000"

when "00011101"=>b<="01111100"

when "00011110"=>b<="10000000"

when "00011111"=>b<="10000011"

when "00100000"=>b<="10000111"

when "00100001"=>b<="10001011"

when "00100010"=>b<="10001111"

when "00100011"=>b<="10010010"

when "00100100"=>b<="10010110"

when "00100101"=>b<="10011001"

when "00100110"=>b<="10011101"

when "00100111"=>b<="10100000"

when "00101000"=>b<="10100100"

when "00101001"=>b<="10100111"

when "00101010"=>b<="10101011"

when "00101011"=>b<="10101110"

when "00101100"=>b<="10110001"

when "00101101"=>b<="10110100"

when "00101110"=>b<="10110111"

when "00101111"=>b<="10111010"

when "00110000"=>b<="10111110"

when "00110001"=>b<="11000000"

when "00110010"=>b<="11000011"

when "00110011"=>b<="11000110"

when "00110100"=>b<="11001001"

when "00110101"=>b<="11001100"

when "00110110"=>b<="11001110"

when "00110111"=>b<="11010001"

when "00111000"=>b<="11010011"

when "00111001"=>b<="11010110"

when "00111010"=>b<="11011000"

when "00111011"=>b<="11011011"

when "00111100"=>b<="11011101"

when "00111101"=>b<="11011111"

when "00111110"=>b<="11100001"

when "00111111"=>b<="11100011"

when "01000000"=>b<="11100101"

when "01000001"=>b<="11100111"

when "01000010"=>b<="11101001"

when "01000011"=>b<="11101011"

when "01000100"=>b<="11101100"

when "01000101"=>b<="11101110"

when "01000110"=>b<="11110000"

when "01000111"=>b<="11110001"

when "01001000"=>b<="11110011"

when "01001001"=>b<="11110100"

when "01001010"=>b<="11110101"

when "01001011"=>b<="11110110"

when "01001100"=>b<="11110111"

when "01001101"=>b<="11111000"

when "01001110"=>b<="11111001"

when "01001111"=>b<="11111010"

when "01010000"=>b<="11111011"

when "01010001"=>b<="11111011"

when "01010010"=>b<="11111101"

when "01010011"=>b<="11111101"

when "01010100"=>b<="11111101"

when "01010101"=>b<="11111110"

when "01010110"=>b<="11111110"

when "01010111"=>b<="11111110"

when "01011000"=>b<="11111111"

when "01011001"=>b<="11111111"

when "01011010"=>b<="11111111"

when "01011011"=>b<="11111111"

when "01011100"=>b<="11111111"

when "01011101"=>b<="11111110"

when "01011110"=>b<="11111110"

when "01011111"=>b<="11111110"

when "01100000"=>b<="11111101"

when "01100001"=>b<="11111101"

when "01100010"=>b<="11111101"

when "01100011"=>b<="11111011"

when "01100100"=>b<="11111011"

when "01100101"=>b<="11111010"

when "01100110"=>b<="11111001"

when "01100111"=>b<="11111000"

when "01101000"=>b<="11110111"

when "01101001"=>b<="11110110"

when "01101010"=>b<="11110101"

when "01101011"=>b<="11110100"

when "01101100"=>b<="11110011"

when "01101101"=>b<="11110001"

when "01101110"=>b<="11110000"

when "01101111"=>b<="11101110"

when "01110000"=>b<="11101110"

when "01110001"=>b<="11101011"

when "01110010"=>b<="11101001"

when "01110011"=>b<="11100111"

when "01110100"=>b<="11100101"

when "01110101"=>b<="11100011"

when "01110110"=>b<="11100001"

when "01110111"=>b<="11011111"

when "01111000"=>b<="11011101"

when "01111001"=>b<="11011011"

when "01111010"=>b<="11011000"

when "01111011"=>b<="11010110"

when "01111100"=>b<="11010011"

when "01111101"=>b<="11010001"

when "01111110"=>b<="11001110"

when "01111111"=>b<="11001100"

when "10000000"=>b<="11001001"

when "10000001"=>b<="11000110"

when "10000010"=>b<="11000011"

when "10000011"=>b<="11000000"

when "10000100"=>b<="10111110"

when "10000101"=>b<="10111010"

when "10000110"=>b<="10110111"

when "10000111"=>b<="10110100"

when "10001000"=>b<="10110001"

when "10001001"=>b<="10101110"

when "10001010"=>b<="10101011"

when "10001011"=>b<="10100111"

when "10001100"=>b<="10100100"

when "10001101"=>b<="10100000"

when "10001110"=>b<="10011101"

when "10001111"=>b<="10011001"

when "10010000"=>b<="10010110"

when "10010001"=>b<="10010010"

when "10010010"=>b<="10001111"

when "10010011"=>b<="10001011"

when "10010100"=>b<="10000111"

when "10010101"=>b<="10000000"

when "10010110"=>b<="10000000"

when "10010111"=>b<="01111100"

when "10011000"=>b<="01111000"

when "10011001"=>b<="01110100"

when "10011010"=>b<="01110000"

when "10011011"=>b<="01101100"

when "10011100"=>b<="01101000"

when "10011101"=>b<="01100100"

when "10011110"=>b<="01100000"

when "10011111"=>b<="01011011"

when "10100000"=>b<="01010111"

when "10100001"=>b<="01010011"

when "10100010"=>b<="01001111"

when "10100011"=>b<="01001011"

when "10100100"=>b<="01000110"

when "10100101"=>b<="01000001"

when "10100110"=>b<="00111110"

when "10100111"=>b<="00111001"

when "10101000"=>b<="00110101"

when "10101001"=>b<="00110001"

when "10101010"=>b<="00101100"

when "10101011"=>b<="00101000"

when "10101100"=>b<="00100011"

when "10101101"=>b<="00011111"

when "10101110"=>b<="00011011"

when "10101111"=>b<="00010110"

when "10110000"=>b<="00010001"

when "10110001"=>b<="00001101"

when "10110010"=>b<="00001001"

when "10110011"=>b<="00000100"

-- when "10110100"=>b<="00000000"

when others=>null

end case

q(7 downto 0)<=b(7 downto 0)

end process

end Behavioral

锯齿波可以有三角波的程序来改。

你将这几段程序合在一起就可以了,可以用拨码开关对输出哪种波形进行选择,频率可以对输入的时钟进行分频来改变。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11446663.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存