Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Ternary conditional operator
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Verilog=== [[Verilog]] is technically a [[hardware description language]], not a programming language though the semantics of both are very similar. It uses the {{code|?:}} syntax for the ternary operator. <syntaxhighlight lang="verilog"> // using blocking assignment wire out; assign out = sel ? a : b; </syntaxhighlight> This is equivalent to the more verbose Verilog code: <syntaxhighlight lang="verilog"> // using blocking assignment wire out; if (sel === 1) // sel is 1, not 0, x or z assign out = a; else if (sel === 0) // sel is 0, x or z (1 checked above) assign out = b; else // sel is x or z (0 and 1 checked above) assign out = [comment]; // a and b are compared bit by bit, and return for each bit // an x if bits are different, and the bit value if the same </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)