Bytes question..

This is a discussion on Bytes question.. within the C Programming forums, part of the General Programming Boards category; Well.. I'm triying to do a file compressor, and I need to read each byte and convert it to decimal, ...

  1. #1
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193

    Bytes question..

    Well.. I'm triying to do a file compressor, and I need to read each byte and convert it to decimal, is the number of bites on a byte 8? or it can change depending on different things?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,597
    I'm triying to do a file compressor, and I need to read each byte and convert it to decimal, is the number of bites on a byte 8? or it can change depending on different things?
    Check CHAR_BIT from <limits.h>
    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
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    The number of bytes in a byte is one: ALWAYS. And no, not all bytes are created equal. Some have 8 bits while others have 7 or even 12.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,597
    The number of bytes in a byte is one: ALWAYS.
    That is self-evident, though I believe that by "bites" lautarox meant "bits", otherwise the real question is when lautarox had his/her last meal that he/she has to resort to eating bytes

    And no, not all bytes are created equal. Some have 8 bits while others have 7 or even 12.
    However, the C Standard guarantees that bytes will be of at least 8 bits.
    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

  5. #5
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Mmm.. my plan was to convert an 8 bits, a supposed byte, to decimal, and give it a reference number, like this, for example, 64 = 1, another byte, 68 = 2, so 1+2 equals 3, so I give that two bites a reference number that is 3, and then I output it into a file reducing the original size..

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by laserlight
    However, the C Standard guarantees that bytes will be of at least 8 bits.
    No arguments there. It does not guarantee a constant size though. Which is why laserlight mentioned CHAR_BIT. In any event, I know "bites" meant "bits" but I am just being picky. Oh and lautarox, remind me about your other code. I keep forgetting to upload it to you and its not on this machine.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,597
    Mmm.. my plan was to convert an 8 bits, a supposed byte, to decimal, and give it a reference number, like this, for example, 64 = 1, another byte, 68 = 2, so 1+2 equals 3, so I give that two bites a reference number that is 3, and then I output it into a file reducing the original size..
    I am not sure how that is supposed to work. How would you know that 3 means the byte pair (64, 68) and not (68, 64)?

    Have you searched the Web for compression algorithms?
    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

  8. #8
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Read up on Huffman encoding. I think you will be pleasantly enlightened.

  9. #9
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Well.. huffman encoding is based on prediction, I want my own creation =P, about knowing the byte pair, i can have numbers for each pair..
    Thinking a little bit more, the size of the byte won't be a problem, because I stiil can read, convert and then read the conversion again..
    Last edited by lautarox; 10-16-2008 at 01:40 PM.

  10. #10
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Actually, you can still use variable Huffman encoding. There are better forms of compression for what you are describing though. Such as (God why can't I think of the name of it... its used in ZIP files.... guh. I will have to google it since I am drawing a blank for some reason). You can use a sliding window to reference previous instances of a block of data. LZ compression, there we go. Jesus. I didn't need to google it guys, I was just having a blond moment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. Memory quiz, question 2
    By pheres in forum C++ Programming
    Replies: 4
    Last Post: 06-08-2008, 05:46 AM
  3. Shared class members over Dll Boundary
    By Elysia in forum C++ Programming
    Replies: 19
    Last Post: 11-13-2007, 12:43 PM
  4. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  5. controlling how many bytes a variable takes up
    By mike_532532 in forum C++ Programming
    Replies: 6
    Last Post: 07-30-2007, 04:20 AM

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