Like Tree2Likes
  • 2 Post By iMalc

How do I work with data that is larger than 4 bytes at a time?

This is a discussion on How do I work with data that is larger than 4 bytes at a time? within the C Programming forums, part of the General Programming Boards category; like 8 bytes at a time. Read in 8 bytes perform some math then output to file. How would I ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    150

    How do I work with data that is larger than 4 bytes at a time?

    like 8 bytes at a time.
    Read in 8 bytes perform some math then output to file.
    How would I treat this?
    I know I can do it with a DWORD but what would the other be?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,415
    An array?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    You've asked a very broad question and in lots of ways, everybody's answer is valid.

    What are you doing and what do you think makes sense?

    If you want to work with more than four bytes at once, you simply need to work with more than four bytes at once. Does that mean per iteration? Perhaps some inner loop works with a single char, but it iterates more than four times... eight times... with the char variable changing sometimes. Or does that mean that you have to store more than eight bits? In that case, use a bigger type than a single char, or invent a new type.
    Last edited by whiteflags; 01-03-2012 at 07:50 PM.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    150
    Trying to read in eight bytes as if it were a long long int and check to see if it is divisable by two and if so then do some math on it and output it to a file.

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    If it's binary you can pretty much store it any way that makes sense to you. You have to be smart enough to fiddle with bits if there is no native type you want to use.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Once-ler View Post
    Trying to read in eight bytes as if it were a long long int and check to see if it is divisable by two and if so then do some math on it and output it to a file.
    What compiler are you using?

    All the common ones... MinGW, LCC, Pelles, VC++, etc. support 8byte ints... only the old and feeble like Turbo C do not.

    it's a long long int or simply... long long...

  7. #7
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    The double data type is usually eight bytes.
    Quote Originally Posted by The Jargon File
    Microsoft Windows - A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition.

  8. #8
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    Let's just hope that the bytes are intended to be a floating point number then...

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,294
    Quote Originally Posted by Once-ler View Post
    like 8 bytes at a time.
    Read in 8 bytes perform some math then output to file.
    How would I treat this?
    I know I can do it with a DWORD but what would the other be?
    There are so many possible answers I don't know where to start.

    You may as well be asking how to transport 8 people from your house to town. Are 8 pairs of rollerskates okay? What about a private jet? Give some constraints, and an explanation of what you're doing.
    laserlight and whiteflags like this.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  10. #10
    Registered User
    Join Date
    Nov 2011
    Posts
    150
    code blocks with GNU GCC compiler

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Once-ler View Post
    code blocks with GNU GCC compiler
    Then you should have the type: long long int which is 8 bytes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to write two bytes at a time to a file?
    By Flotonic in forum C Programming
    Replies: 11
    Last Post: 05-28-2011, 03:58 PM
  2. Pointer Data (bytes)
    By tiagokos in forum C Programming
    Replies: 1
    Last Post: 03-22-2011, 06:20 PM
  3. Replies: 10
    Last Post: 09-22-2009, 11:38 AM
  4. Replies: 8
    Last Post: 01-18-2008, 03:06 AM
  5. Possible to pack smaller data types into larger ones?
    By Heraclitus in forum C Programming
    Replies: 3
    Last Post: 02-09-2003, 02:22 PM

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