Custom Binary Format

This is a discussion on Custom Binary Format within the Windows Programming forums, part of the Platform Specific Boards category; I found a chart for translating ASCII into Binary and other codes at: http://www.pcguide.com/res/tablesASCII-c.html I know you can save text ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Exclamation Custom Binary Format

    I found a chart for translating ASCII into Binary and other codes at:
    http://www.pcguide.com/res/tablesASCII-c.html
    I know you can save text as binary, but I was wondering, is there a way to make a program that
    will save text as binary but in a different binary format?
    For an example,

    A = 01000001
    B = 01000010

    But instead of that I would have it like this.

    A = 00000001
    B = 00000010

    As you see that would make it so that you have to have a program specially designed to read it,
    not just any word processor would do. So it would be a custom format. Can this be done? And if
    so, how?
    Thanks, August.
    (P.S. I would want program only to be able to read A-Z and 0-9 only.)

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    There are numerous ways to approach this problem. A very simple method that comes to mind is to make a 256 element array of integers. Each element in this array would correspond to an ascii value. For instance, array element 'a' would be 97 decimal or 0x61. Then stored at that location you would put the value you would like to use to represent this in your program. So you might decide this would be 0000 0011 binary or 3 in decimal. Likewise you could have another array to convert the other direction.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Simply encode the data and then write to disk. Do the reverse during input. Enhance the process via multithreading.

    Kuphryn

  4. #4
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    I may be missing the point but can you just subtract 64 from the ASCII value before you encode to binary.
    Last edited by UnclePunker; 04-22-2005 at 10:24 AM.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  5. #5
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    That could be done, yes. If that's the only encoding you are wanting to do, it would work fine. Then in reading the file you would add 64 to the value again.

  6. #6
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Yes. Tell me how you can add or subtract 64 from the binary code.

  7. #7
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Well, when saving a file, one approach would be to put the entire contents of the file to be into an allocated character array and then loop through each element, subtracting 64 from each value. The same applies for reading in. Store the entire file contents into an allocated character array and then loop through, adding 64 to each element.

  8. #8
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I think I understand what you are saying but I don't know how to do all of those things, could you give me an example to work with?

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    if you want 'a' to be 0 and 'b' to be 1 then you would subtract 65
    Code:
    char Array[]={
    "some text"
    };
    for (int i=0;Array[i]!=0;i++)
       Array[i]-=65;
    Since the value of Z is 90 and the value of a is 97 you might want to check the range of the char values before modifying them but that depends on how you want things encoded.

  10. #10
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I still don't get it
    I'm only a newbie

  11. #11
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Well, if you're that much of a newbie, I really suggest you do more work with base C or C++ programming. Win32 API is just a bunch of predefined C and C++ functions, data types, structures, ect. and if you don't know hoe they work, you're gonna have a pretty hard time learning it. Spend at least a few weeks working with C or C++ (I prefer C, but most prefer C++) and then see how API goes for you.

  12. #12
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Guess you'r right, thanks anyway though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  2. data input in binary format
    By aamirsyed in forum C Programming
    Replies: 1
    Last Post: 06-30-2004, 06:27 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Windows binary format
    By squid in forum Windows Programming
    Replies: 2
    Last Post: 06-10-2003, 10:43 PM
  5. Custom texture format?
    By Eber Kain in forum C++ Programming
    Replies: 1
    Last Post: 02-03-2002, 09:50 AM

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