①Verilog has a ternary conditional operator ( ? : ) much like C:

(condition ? if_true : if_false)

This can be used to choose one of two values based on condition (a mux!) on one line, without using an if-then inside a combinational always block.

Examples:

(0 ? 3 : 5)     // This is 5 because the condition is false.
(sel ? b : a)   // A 2-to-1 multiplexer between a and b selected by sel.

Given four unsigned numbers, find the minimum. Unsigned numbers can be compared with standard comparison operators (a < b). Use the conditional operator to make two-way min circuits, then compose a few of them to create a 4-way min circuit. You'll probably want some wire vectors for the intermediate results.

module top_module (input [7:0] a, b, c, d,output [7:0] min);//
assign min=(((c<d)?c:d)<((a<b)?a:b))?((c<d)?c:d):((a<b)?a:b);
endmodule

② Given a 100-bit input vector [99:0], reverse its bit ordering.

module top_module( input [99:0] in,output [99:0] out
);always@(*) beginfor(int i=0;i<100;i++)beginout[i]=in[99-i];endend
endmodule

③A "population count" circuit counts the number of '1's in an input vector. Build a population count circuit for a 255-bit input vector.

module top_module( input [254:0] in,output [7:0] out );
always@(*) begin out=8'b00000000;//out初始化for (int i=0;i<=254;i=i+1)beginif (in[i]==1'b1)out=out+1'b1;else out=out+1'b0;endend
endmodule

module top_module (input in1,input in2,input in3,output out);assign out = ~(in1^in2) ^ in3;
endmodule

Conditional ternary operator...相关推荐

  1. Java三目运算符 (Ternary Operator ? :)

    Java三目运算符 (Ternary Operator ? : ) 条件语句? true内容 : false内容 例子1: int a = 1; int b = 2; int getLarge = a ...

  2. 【Swift 60秒】25 - The ternary operator

    0x00 Lesson Swift has a rarely used operator called the ternary operator. It works with three values ...

  3. Conditional, Ternary 运算符的使用

    1. Conditional 条件运算符的使用 1.1 实现 /// 条件语句 struct ConditionalBootcamp: View {@State var showCircle: Boo ...

  4. 在JavaScript中反转字符串的三种方法

    This article is based on Free Code Camp Basic Algorithm Scripting "Reverse a String" 本文基于F ...

  5. c#如何嵌套第三方程序_C#程序演示嵌套条件运算符的示例

    c#如何嵌套第三方程序 C# (or other programming languages also) allows to use a conditional/ternary operator wi ...

  6. java 示例_最佳Java示例

    java 示例 什么是Java? (What is Java?) Java is a programming language developed by Sun Microsystems in 199 ...

  7. 小程序使用sass_如何使用Sass Maps生成所有实用程序类

    小程序使用sass by Sarah Dayan 通过莎拉·达扬 如何使用Sass Maps生成所有实用程序类 (How to generate all your utility classes wi ...

  8. 什么时候应该在ECMAScript 6中使用Arrow函数?

    本文翻译自:When should I use Arrow functions in ECMAScript 6? The question is directed at people who have ...

  9. React.js 学习

    目录 Source Expression and statement: React styling: React Components React props Mapping data to comp ...

最新文章

  1. bootstrap 冻结表格,冻结表头
  2. java 判断题_Java面试题及解析(判断题)
  3. asyn4j -- java 异步方法调用框架
  4. 向别人网页注入js_区块链研究实验室 | Web3 .js基于以太坊的Javascript API
  5. 基克的聚合 机器人_重做秒变神器!基克的聚合成辅助标配
  6. ASP.NET(C#)获取客户端的网卡MAC代码
  7. Java从入门到精通——数据库篇Mongo DB 导出,导入,备份
  8. python求职者的建议_Python 求职和建议-从认识自己出发
  9. [2005.04.24 20:47:26] 实践与思考之窥索[原创]
  10. springBoot+springSecurity 数据库动态管理用户、角色、权限
  11. Application.messagebox对话框样式
  12. 配电室智能监控系统设计及实现分析-Susie 周
  13. Python运算(五)统计statistic模块
  14. 软件工程之结构化方法
  15. python批量查询ip归属地_python3.2批量查询IP地址区域
  16. 送书福利|少儿编程能够一玩就会吗?够胆量的家长,让孩子打卡30天玩会编程!...
  17. freeswitch的呼叫中心模块——mod_callcenter
  18. ***cgy学长爱吃糖果***
  19. spark-submit 提交任务及参数说明
  20. 企业微信代开发自建应用和自建应用的区别分析

热门文章

  1. 4 Debezium抽取部署
  2. vue实现跑马灯抽奖
  3. input type=button与asp:button的区别,以及runat=server的作用
  4. 2021年全球与中国水上巡航行业市场规模及发展前景分析
  5. matlab命令行窗口显示长度设置_设置命令行窗口输出显示格式 | MATLAB format| MathWork...
  6. 转换字母大小写(小写转大写)
  7. 北京交警二环路机动车道“瘦身”,最高“礼遇”骑行人
  8. 算术右移与逻辑右移的转换
  9. perf常用用法简介
  10. 完全格式化硬盘(删除EFI分区)