Long integer to binary pattern

This is a discussion on Long integer to binary pattern within the C Programming forums, part of the General Programming Boards category; Part of a course work question asks to define an unsigned integer and initialise it to the binary pattern: 0101 ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Location
    Northern Ireland
    Posts
    2

    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!
    Last edited by mark522; 12-17-2009 at 02:58 AM.

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    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. #3
    Registered User
    Join Date
    Dec 2009
    Location
    Northern Ireland
    Posts
    2
    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. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how integer stored in binary format in 'c' language
    By pankaj_kumar in forum C Programming
    Replies: 7
    Last Post: 04-01-2009, 08:26 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  3. Looking for data structures for long integer
    By George2 in forum C Programming
    Replies: 1
    Last Post: 06-05-2006, 01:34 AM
  4. Quick, Partiotion, and Insertion Sort
    By silicon in forum C++ Programming
    Replies: 0
    Last Post: 05-18-2005, 08:47 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21