Enhancing hex and binary literal representation #9378
Replies: 3 comments 4 replies
-
The issue is not related to hex or binary literals, they already support all of the suffixes that C# already supports for literal numbers. The issue is that there is no suffix for byte. |
Beta Was this translation helpful? Give feedback.
-
I have hit this situation, but, I think it's not solved by a literal suffix, because few (or no?) built-in operators take and return bytes. So, there is a need to cast results to byte quite often, or even to I'm not sure I consider it a problem that we should solve, though. While it can be inconvenient, it does cause me to think more often about what to do with overflow, which is a more frequent occurrence with the smaller numeric types. |
Beta Was this translation helpful? Give feedback.
-
The logical operators are all inherently unsigned, there's no concept of a sign for AND, OR, NAND, NOR or NOT (only C#'s So something like this should not require acrobatics: byte reg &= ~0xBF |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Do others here find it a bit frustrating to be able to write this:
but not
where
reg
is declared asbyte
.If there was a way to make the literal be treated as a specific basic type (like byte) this kind of code might be easier to write and look less cluttered than it does today.
So would it not be helpful to extend the notation used for hex literals to allow something like this:
This seems like it would be non-breaking and make such code more readable without the mental gymnastics needed to compensate for it being treated as a signed 32 bit int, in cases where we are doing bit manipulation and interacting with hardware and stuff, this would make such code more intuitive.
Thoughts...
Beta Was this translation helpful? Give feedback.
All reactions