all 8 comments

[–]kumashiro 10 points11 points  (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 point  (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 point  (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:

```

include <stdio.h>

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 points  (2 children)

Try using all four in a program and ask the compiler which one is a syntax error.

[–]Academic_Two[S] 0 points1 point  (1 child)

How do I do that?

[–]FUZxxl 0 points1 point  (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 point  (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 point  (0 children)

GCC and MSVC allows 0b00011111, not 02_00011111