Search
Star
Feedback
Setup for Free
© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
Branchless way to convert bool to int? - Modular
M
Modular
•
3y ago
•
8 replies
sa-code
Branchless way to convert bool to int?
Right now I do something like
# assuming b is a bool
let x = 1 if b else 0
# assuming b is a bool
let x = 1 if b else 0
Is there a way to do this in a branchless way
?
b.to_int()
b.to_int()
doesn
't exist
Modular
Join
This server is the home of the MAX and Mojo community! Join us to chat about all things Modular.
20,199
Members
View on Discord
Resources
ModelContextProtocol
ModelContextProtocol
MCP Server
Similar Threads
Was this page helpful?
Yes
No
Similar Threads
How to convert a byte to integer?
M
Modular / questions
3y ago
Is it possible to convert an Int to a String at comp time?
M
Modular / questions
2y ago
convert error: 'Int' to 'IntLiteral' trying to implement the FloatLiteral.__round__(ndigits) method
M
Modular / questions
2y ago
Fastest way to count trailing zeros from a SIMD[Bool,32]?
M
Modular / questions
2y ago