小编Tri*_*7er的帖子

Verilog问号(?)运算符

我正在尝试将Verilog程序翻译成VHDL,并偶然发现了一个?在Verilog程序中使用问号()运算符的语句.

以下是Verilog代码;

1  module music(clk, speaker);
2  input clk;
3  output speaker;
4  parameter clkdivider = 25000000/440/2;

5  reg [23:0] tone;
6  always @(posedge clk) tone <= tone+1;

7  reg [14:0] counter;
8  always @(posedge clk) if(counter==0) counter <= (tone[23] ? clkdivider-1 : clkdivider/2-1); else counter <= counter-1;

9  reg speaker;
10  always @(posedge clk) if(counter==0) speaker <= ~speaker;
11  endmodule
Run Code Online (Sandbox Code Playgroud)

我不明白第8行,请问有谁可以对此有所了解?我在asic-world网站上看到问号是Z角色的Verilog替代品.但我不明白为什么在这种情况下使用它.

亲切的问候

verilog operators vhdl

6
推荐指数
2
解决办法
6万
查看次数

如何确定x和y是否存在于满足等式的整数X集合中

我在准备考试的时候遇到了考试问题而且我坚持了下来.问题是:

设计一种算法,给定一组正整数X,确定方程x 5 + xy-y 2 = y 3是否具有x和y都属于X的解.

没有涉及编程,只是算法设计.有人可以分享他们的想法吗?

蛮力是不可接受的

algorithm

5
推荐指数
1
解决办法
363
查看次数

VHDL综合警告FF/Latch的常数值为0

我正在尝试一些基本上涉及使用FPGA并从温度传感器读取值的代码.

代码如下:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

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

entity ds18b20 is
    Port ( clk      : in  STD_LOGIC;        --50Mhz oscillator onboard
       dq       : inout  STD_LOGIC;
       temp_h : out  STD_LOGIC_VECTOR (7 downto 0);
       temp_l : out  STD_LOGIC_VECTOR (7 downto 0);
          temperature   : out STD_LOGIC_VECTOR (11 downto 0));
end ds18b20;

architecture Behavioral of ds18b20 is

--RESET  :  RESET AND PRESENCE PULSE
--CMD_CC …
Run Code Online (Sandbox Code Playgroud)

warnings synthesis vhdl

4
推荐指数
1
解决办法
3714
查看次数

Scanner,nextInt和InputMismatchException

我正在尝试读取一个文本文件,然后使用Java中的nextInt()函数在循环中打印出整数.我的文本文件的格式如下:

a 2000 2
b 3000 1
c 4000 5
d 5000 6
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

public static void main(String[] args) throws FileNotFoundException {

  String fileSpecified = args[0] + ".txt";

  FileReader fr = new FileReader(fileSpecified);
  BufferedReader br = new BufferedReader (fr);
  Scanner in = new Scanner (br);

  while (in.hasNextLine()) {
    System.out.println ("next int = " + in.nextInt());
  }
}
Run Code Online (Sandbox Code Playgroud)

我总是得到的错误是:

Exception in thread "main" java.util.InputMismatchException
           at java.util.Scanner.throwFor(Unknown Source)
           at java.util.Scanner.next(Unknown Source)
           at java.util.Scanner.nextInt(Unknown Source)
           at java.util.Scanner.nextInt(Unknown Source)
Run Code Online (Sandbox Code Playgroud)

每次在任何程序中使用nextInt()时都会出现此错误.

java file-io java.util.scanner

2
推荐指数
1
解决办法
8864
查看次数

Java分隔符跳过一个单词

我正在读取一个文本文件并将该文本文件中的一组唯一单词存储到一个ArrayList中(如果有更好的结构,请建议这样做).我正在使用扫描仪扫描文本文件并将分隔符指定为""(空格),如下所示;

    ArrayList <String> allWords = new ArrayList <String> ();
    ArrayList <String> Vocabulary = new ArrayList <String> ();
    int count = 0;

    Scanner fileScanner = null;
    try {
        fileScanner = new Scanner (new File (textFile));

    } catch (FileNotFoundException e) {
        System.out.println (e.getMessage());
        System.exit(1);
    }

    fileScanner.useDelimiter(" ");

    while (fileScanner.hasNext()) {

        allWords.add(fileScanner.next().toLowerCase());

        count++;

        String distinctWord = (fileScanner.next().toLowerCase());
        System.out.println (distinctWord.toString());

        if (!allWords.contains(distinctWord)) {

            Vocabulary.add(distinctWord);

        }
    }
Run Code Online (Sandbox Code Playgroud)

因此,在打印词汇表的内容之后,在每个单词之后都会跳过一个单词.因此,例如,如果我有以下文本文件;

"敏捷的棕色狐狸跳过了懒狗"

印刷的内容是"快速狐狸懒",然后它给我一个错误;

Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Unknown Source)
    at java.util.Scanner.next(Unknown Source)
    at *java filename*.getWords(NaiveBayesTxtClass.java:82)
    at …
Run Code Online (Sandbox Code Playgroud)

java unique java.util.scanner

2
推荐指数
1
解决办法
372
查看次数

在Java中生成任意两个随机字符

如何在两个特定字符之间生成随机字符?例如; 我想生成'h'或'v'中的任何一个.

谢谢

java random character range

1
推荐指数
1
解决办法
3663
查看次数

将数据从一个指针复制到另一个seg错误

我的C技能有点生疏,有一天我正在完成一项任务并遇到了一些指示.我不知道为什么,但这完全困扰了我.所以,请原谅我,如果解决方案是微不足道的.

我写了下面的代码,将数据复制到另一个指针.我不想使用memcpy,strcpy或任何其他功能.

char *word = "hello world!";
char *ptra = NULL;

ptra = malloc(strlen(word) + 1);

for (; word != '\0'; word++, ptra++) {
    *ptra = *word;
}

*ptra = '\0';
Run Code Online (Sandbox Code Playgroud)

现在,当我编译它时,我得到一个分段错误.有人可以帮我解决这个问题吗?

c pointers segmentation-fault

1
推荐指数
1
解决办法
2195
查看次数

存储hashmap值的概率

我有一个hashmap,我正在读取一个文本文件并将唯一的单词存储到key中,并在值字段中将该特定单词的频率存储在另一个文本文件中.

现在,我必须跟踪另一个文本文件中出现该单词的概率.我不需要知道如何计算概率,但是,我需要弄清楚的是,当已经采用值字段(单词的频率)时,如何存储与每个键(字)相关联的概率.

你建议我用相同的键创建另一个hashmap,但用概率替换值吗?谢谢!

java probability hashmap

0
推荐指数
1
解决办法
418
查看次数