Need help on c programming bytes handling

This is a discussion on Need help on c programming bytes handling within the C Programming forums, part of the General Programming Boards category; ok here is the problem: you read 3 integer numbers: x,n,p. The program have to ask you to display: -the ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    1

    Need help on c programming bytes handling

    ok here is the problem:

    you read 3 integer numbers: x,n,p. The program have to ask you to display:
    -the number formed of the n bytes from the position p
    -number formed by setting n bytes strting with position p
    -number formed by erasing n bytes starting with position p
    -number formed by reversing n bytes starting with position p.

    I don't even understand the problem. Somebody could help me please? I've worked in C but not this chapter related to bytes.

    Thank You

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Frankly, I don't either.
    Is this the exact wording of the problem?
    What is "position p"? Are you reading from a file? What does "the number formed" mean?

    The info you've provided is too vague to write a program from, so we'll need more details.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    The following is my guess as to what they want you to do:

    Read 3 integers, x, n, and p.

    From there, you need print an altered version of x for each different request. The first request is to print the number x if x was altered as follows:

    1) Take the position p to indicate which byte of x you're dealing with. So if p is 1, you want the first byte of the number.
    2) From p, move forward n bytes. If n is one, just read 1 byte from p.
    3) You have your number. Print it.

    Note, this type of program is probably, first of all, not safe and leaves you the possibility to corrupt n and p, if x is declared first. If x is declared last, you might cause a seg fault.

    Even assuming all goes well, you'll probably be introduced to the issues of endianess.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by boris1979 View Post
    you read 3 integer numbers: x,n,p. The program have to ask you to display:
    -the number formed of the n bytes from the position p
    -number formed by setting n bytes strting with position p
    -number formed by erasing n bytes starting with position p
    -number formed by reversing n bytes starting with position p.

    I don't even understand the problem. Somebody could help me please? I've worked in C but not this chapter related to bytes.
    Bytes or bits?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    134
    I hope u r talking about bits shuffling.

    Convert 'x' in binary, take it in an array. Perform the manipulations as given in ur task. Then again convert binary to decimal and display.
    S_ccess is waiting for u. Go Ahead, put u there.

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Guesswork until the OP explains his homework

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Page File counter and Private Bytes Counter
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 01-31-2008, 03:17 AM
  2. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  3. Shared class members over Dll Boundary
    By Elysia in forum C++ Programming
    Replies: 19
    Last Post: 11-13-2007, 01:43 PM
  4. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 11:36 AM
  5. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 02:54 PM

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