Does anyone know how to output in binary without me having to write a converter myself, it needs to convert text / numbers / ... yeah thats about it.
Any Help would be apreciated...!
Does anyone know how to output in binary without me having to write a converter myself, it needs to convert text / numbers / ... yeah thats about it.
Any Help would be apreciated...!
Style is overrated.
- —₽‚¢‰Î -
Post an example of what you want to write to disk in binary mode.
One solution is ofstream's write().
Kuphryn
All of the things that i want to output are stored in variables but for some examples
Suan //first name
Seith //Last name
12 //Strength
13 //...
15 //...
13 //...
10 //...
67 //hp
85 //maxhp
12 //mp
12 //maxmp
Style is overrated.
- —₽‚¢‰Î -
why do you need to output it as binary?
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
I'd just like it so that no one can change their savefile without atleast going through some trouble of converting into readable text and even then some people are to dumb to evern think of converting the binary to normal text.
Style is overrated.
- —₽‚¢‰Î -
when I want to do that, I usually just shift the characters (using the ASCII table) by a random number of positions and put that number somewhere in the file, for example:
now the file will look something like this (assuming the random number was 56)Code:int RANDNUM=1+rand()%100; //any number between 1 and 100 ofile<<"N"<<RANDNUM<<":"<<flush; //output the number at the beginning of the file for(...) //loop through all characters (including spaces, newlines, numbers, etc.) ofile<<static_cast<char>(static_cast<int>(THISCHAR+RANDNUM)); //shift and write the chars
now when you read in teh file, discard the N, read in the number (56 in this case), discard the colon (, and start reading in the characters, decrementing each by the number you just read in... This should in now way be considered 'secure', but it's just something to keep the average user from fking around with the file... although it probably won't do much... another thing you could do is save it as .ico or something, so people might think it's an icon and not touch it... but I wouldn't go that far...Code:N56:¸Ïj¦ô°X·Ìx#‚:T;t4I™÷6æÜäg¯j½Ék”ƒa8|ž]I~DSCûÀSÚµ¦“t“}¬{¡\{0.H8¨¾€Ý˜õ<tÏQM+×c
one thing I would do though, is supply a way to edit the savefile, but keep it somewhat secure... maybe through a password or something, but sometimes it becomes necessary to backup/restore/edit a file...
Last edited by major_small; 04-22-2004 at 08:56 PM. Reason: added more
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
You could use the bitset stl class. Its contructor accepts a long. There is the << operator overloaded for stream, but I do not know how the output should like.
Nothing more to tell about me...
Happy day =)
Here's an example that converts between various bases. It uses bitset to display in binary.
Note: I had to change the name to base.txt, from base.cpp... Apparently the new board software won't allow a cpp file.
... or you could read the FAQ...
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Oh! ... You don't want to use bitset then.I'd just like it so that no one can change their savefile without atleast going through some trouble...
This is a little confusing...
The "binary" file format isn't really binary. When you save a file in binary format, the bytes are written directly to the file without any re-formatting. ...Well everything in the computer is binary, but if you open a binary file with a text editor, you will NOT see a bunch of ones and zeros.
The text format is a special feature. When you save a file as text, all it does is add a carrage-return and/or linefeed (depending on how our system stores text) to the end of each line.
So, if you save a null-terminated c-style string, the zero at the end of the string will be replaced by a carrage-return/linefeed. If you save it as "binary" the ASCII characters will be saved as normal ASCII characters, and the null-terminating zero will be written to the file. If you then open this "binary" file with a text editor, you will see the text, but new lines won't start on one line down.
The reverse is true when you open a file as text. The compiler throws-out the carrage return/linefeed, and replaces it with a zero (in the case of a c-style string), or formats it as a C++ string.
So, try what major_small suggested, or look into XOR (exclusve or) encryption.