Thread: printing selected bytes of an int variable

  1. #16
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by mitakeet
    though how you write portable code without sizeof is beyond me.
    On types. As in, "preferably on objects" (like what I had posted earlier).
    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.*

  2. #17
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Depending on what the original poster _really_ wants, CHAR_BIT is not necessarily tho most portable code. He probably wants the last octet of the number, not whatever the system happens to call a byte.

  3. #18
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Rashakil Fol
    Depending on what the original poster _really_ wants, CHAR_BIT is not necessarily tho most portable code.
    *bangs head on deask*
    Quote Originally Posted by Rashakil Fol
    He probably wants the last octet of the number, not whatever the system happens to call a byte.
    *moves keyboard*
    *resumes head banging*


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #19
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    Original poster (She),

    I think I actually figured out which way the numbers need to be written to the file. and I used char pointers to put it that way. The only problem is that the file needs to be read by another application and if the format is wrong it all goes to hell. and I found that it was not a matter of which order the bytes are written in for a given number, but that it looks for specific bytes and disregards the rest of the bytes in the number. I'm on a tight schedule, so I won't spend time right now trying to make the code super portable and efficient. My boss is going for completeness. I will however save this whole thread and if time is left at the end of the project I will deffinetly use it to improve the code. Unless I run into the above addressed problems before that time, then I'll have to do it.
    I know it's a bad approach, but stipid corporate leaders need results. Plus I'm not very very proffecient in C++.

    thanks a lot guys,

    AS.
    Last edited by earth_angel; 07-14-2005 at 06:28 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Frustated with mess table printing
    By benedicttobias in forum C Programming
    Replies: 6
    Last Post: 04-16-2009, 05:50 PM
  2. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  3. Switch/case Problems (long code in post)
    By Wraithan in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2005, 06:40 PM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM