# Thread: Long integer to binary pattern

1. ## Long integer to binary pattern

Part of a course work question asks to define an unsigned integer and initialise it to the binary pattern:
0101 111 0001 1000 1001 0010 1101 0011

i dont no what exactly this means. Surley every number has a binary equivalent but if i chage a number into binary its not necessarly look like that?

Sorry guys im just new to C! Trying to learn as i go!

2. It's a stupid question since it assumes that integers are 32 bits. Also, the question fails to mention whether or not endianness should be considered (I'm guessing yes, otherwise the question would be pointless).

3. well the full question is:

define an unsigned long integer and initialise it to the binary pattern
0101 111 0001 1000 1001 0010 1101 0011:
Using hexadecimal notation print the hex value on the console.
Write a function to print a long integer on the console in the hex and binary form. Now perform the following operations on the pattern and print out the results of each operation in hex and binary.
Right shift binary pattern by 4 bits
Left shift the pattern by 6 bits
AND the value with the long int 0x3
AND the value with the char 0x3
OR the value with the unsigned short 0xf00f
Exclusive OR the value with the long int 0xF0F0F0F0

The problem is understanding what he actualy wants me to do. some of it is so wrapped up in gargon it confuses me. especialy when this is a new subject. I no its alot to ask but cld some one mayb bullet point the steps for me i have tried but i realy dont understand. and i cant find anyting on the internet about c programing and binary patterns.

4. I would start with converting the binary pattern to hex by hand, and then simply assign it to an unsigned long int. Converting binary to hex is very easy since you can simply deal with one byte at a time. Hex values in C begin with 0x, e.g. 0xFF is 255 in decimal.

Code:
```unsigned long int hex = 0xFF;
printf("%lX\n", hex);```
Or you could just store the binary pattern as a string and use strtoul to convert it to a long. That would make printing it in binary easy, but I guess that's cheating a bit.

Question 20.10
C Programming Tips #1

Your binary pattern seem to be missing a bit though:
0101 111 0001 1000 1001 0010 1101 0011