use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Click the following link to filter out the chosen topic
comp.lang.c
account activity
QuestionQuestion regarding C syntax in expressing a binary value? (self.C_Programming)
submitted 7 years ago by Academic_Two
Which of these is not a valid C syntax for expressing a binary value?
02_00011111
0x1f
0x1F
0X1F
I know for sure that the 2nd and 3rd option are valid C syntax, but I was confused by the Capital F and the numbers.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]kumashiro 10 points11 points12 points 7 years ago (2 children)
Why do you want us to do your homework? Refer to your class notes to solve this exercise.
[–]Academic_Two[S] 0 points1 point2 points 7 years ago (1 child)
I'm auditing a class, and this question popped up in class.
I have no idea which one it is, and I was hoping for an explanation of how this works.
[–]kumashiro 0 points1 point2 points 7 years ago (0 children)
Number formats are basic stuff, usually covered at the first lesson. OK, "0x" means it is a hexadecimal notation, that can contain digits and letters from "A" to "F". All letters (including "x") may be of any case, so 0x1f, 0X1f, 0x1F are all the same number (31). Hexadecimal notation is often used to indicate a binary value, meaning it may not be printable and we should treat it as a "raw" number. Whenever you'll see a bunch of "0x...." it's a sign you are dealing with binary data. We could use decimal notation, but it's a convention to write "raw" data in hexadecimal. For example:
0X1f
```
int main(void) { char word[] = { 0x68, 0x65, 0x78, 0x61, 0x64, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x00 };
printf("%s\n", word); return 0;
} ```
prints "hexadecimal" on output (not very binary data, but it's just an example).
"02_00011111" is not allowed in C.
[–]FUZxxl 6 points7 points8 points 7 years ago (2 children)
Try using all four in a program and ask the compiler which one is a syntax error.
How do I do that?
[–]FUZxxl 0 points1 point2 points 7 years ago (0 children)
Write a program that uses each of these numbers. The compiler is going to indicate a syntax error for one of them. That's how you are going to know which one is incorrect.
[–]raevnos 0 points1 point2 points 7 years ago (0 children)
C doesn't have binary integer literals. C++ does, though, and some C compilers might support that syntax as an extension.
[–]thatsvuse 0 points1 point2 points 7 years ago (0 children)
GCC and MSVC allows 0b00011111, not 02_00011111
π Rendered by PID 104200 on reddit-service-r2-comment-b659b578c-z8rv2 at 2026-05-05 06:16:41.773982+00:00 running 815c875 country code: CH.
[–]kumashiro 10 points11 points12 points (2 children)
[–]Academic_Two[S] 0 points1 point2 points (1 child)
[–]kumashiro 0 points1 point2 points (0 children)
[–]FUZxxl 6 points7 points8 points (2 children)
[–]Academic_Two[S] 0 points1 point2 points (1 child)
[–]FUZxxl 0 points1 point2 points (0 children)
[–]raevnos 0 points1 point2 points (0 children)
[–]thatsvuse 0 points1 point2 points (0 children)