Reversal of bytes when reading int from binary file! Programming Software Development by hmortensen … 00 00 or 218103808 in dec.. Why/how does this reversal happen???? Thanks for any comment on this small issue. - Hmortensen Question about reversal and array storage for Palindrome Programming Software Development by xerA … 0;[/COLOR] [COLOR=#0000ff]char[/COLOR][COLOR=#000000] reversal([/COLOR][COLOR=#0000ff]char[/COLOR][COLOR=#000000] palinCan[SIZE… (!infile.eof()); } [COLOR=#0000ff]char[/COLOR][COLOR=#000000] reversal()[/COLOR] { [COLOR=#0000ff]for[/COLOR](j = strlen(palinCan); …the loop and return the result into the reversal array for comparison. I've tried a few… Strings: Reversal Programming Software Development by Dave Sinkula This is yet another example of reversing a string. This version modifies the original, reversing the string in place. [I]See also [url=http://www.daniweb.com/code/snippet522.html]Strings: Reversal, Part 2[/url][/I]. String Reversal without using indexing. Programming Software Development by Jaks_maths Used recursion to reverse the string. Another method for string reversal. Byte Reversal Programming Software Development by jralexander137 … figuring out what exactly I'm missing in this Byte reversal method. For example is should take 0x01020304 and flip the… Re: Byte Reversal Programming Software Development by Dave Sinkula … figuring out what exactly I'm missing in this Byte reversal method. For example is should take 0x01020304 and flip the… Re: Reversal of bytes when reading int from binary file! Programming Software Development by dkalita its because of the endianness. Read about Little endian and big endian theory. Re: Reversal of bytes when reading int from binary file! Programming Software Development by hmortensen [QUOTE=dkalita;1022739]its because of the endianness. Read about Little endian and big endian theory.[/QUOTE] Ok, so and int (and every other datatype) can be represented in two ways, LSB left or right. But my additional question now is (google didn't help on this one).. Is this something I can force my compiler to handle for me? I normally … Re: Reversal of bytes when reading int from binary file! Programming Software Development by Dave Sinkula You kinda need to know whether the binary contains LE or BE data. Some somewhat related FAQs: [url]http://c-faq.com/misc/endiantest.html[/url] [url]http://c-faq.com/cpp/ifendian.html[/url] [url]http://c-faq.com/misc/byteswap.html[/url] Or perhaps consider a text file. Re: Reversal of bytes when reading int from binary file! Programming Software Development by hmortensen [QUOTE=Dave Sinkula;1023183]You kinda need to know whether the binary contains LE or BE data. Some somewhat related FAQs: [url]http://c-faq.com/misc/endiantest.html[/url] [url]http://c-faq.com/cpp/ifendian.html[/url] [url]http://c-faq.com/misc/byteswap.html[/url] Or perhaps consider a text file.[/QUOTE] As I wrote in the original … Re: Reversal of bytes when reading int from binary file! Programming Software Development by Dave Sinkula [QUOTE=hmortensen;1023194]As I wrote in the original questinon, I do know what I got.. Its a PNG file! Sooo, text file is not an option. ;) [/QUOTE]Hm. I don't see the mention -- perhaps it's my eyesight. But no matter. Clarification achieved. [QUOTE=hmortensen;1023194]And I do know how to test and swap. But the question now is where/how does … Re: Reversal of bytes when reading int from binary file! Programming Software Development by hmortensen Thanks for all your help guys, As it turned out all my problems arose, as the first project i did was with TGA files, where the header information is in little-endian format, so ofcourse it worked. And then when working with PNG files where the header chunk is in big-endian, it didn't. So I was focokused on the different project styles (with and … Re: Interview Challenge (Word Reversal) Programming Software Development by Killer_Typo …, _TCHAR* argv[]) { cout << "Method one for string reversal" << endl; cout << "==============================" <…;< endl; cout << "Method Two for string reversal" << endl; cout << "==============================" <… Re: String Reversal Programming Software Development by wildgoose Technically that's not a string reversal. If you were to push your characters into a buffer, then reverse them, that's a string reversal! But your code appears to be okay! Do you have a specific problem? Re: Interview Challenge (Word Reversal) Programming Software Development by Lerner … user defined container to hold words parsed from input before reversal is accomplished. Re: Interview Challenge (Word Reversal) Programming Software Development by Killer_Typo … user defined container to hold words parsed from input before reversal is accomplished.[/quote] i had read online that strtok may… Re: Bit Reversal Programming Software Development by Tribhu Nice and informative article and IMO for some thing like bit order reversal we can not think much of portability. One suggestion, we can combine two algos here: 1. Calculate the bit reversed values using the zot() 2. Put these values in array indexes as in fum() Now one can access the reversed values using the array indexes. ~Trib reverse words in a string Programming Software Development by Dhan_1 Reversal of words in a string. i.e., "Jack is a good boy" into "boy good a is Jack" Reversal of fortune Community Center by GuyClapperton Here we have it - only days after it emerged the the European Union was censoring an image on Wikipedia it's [URL="http://www.guardian.co.uk/technology/2008/dec/09/wikipedia-ban-reversed"]changed its mind[/URL]. The image, from the Scorpions' 1976 album, Virgin Killers, can now be seen on the Wikipedia site - it depicts a nude female … Re: Question about reversal and array storage for Palindrome Programming Software Development by Ancient Dragon This is a c++ program, why are you using c-style char arrays. Unless your instructore requires it you should probably be using std::string as input buffer. You do loop is all wrong. Use a while loop instead for better control. [code] std::string inbuf; while( getline(infile,inbuf) ) { // blabla } [/code] now all you have to do is creae … Re: Question about reversal and array storage for Palindrome Programming Software Development by xerA [quote=Ancient Dragon;271854]This is a c++ program, why are you using c-style char arrays. Unless your instructore requires it you should probably be using std::string as input buffer. You do loop is all wrong. Use a while loop instead for better control. [code] std::string inbuf; while( getline(infile,inbuf) ) { // blabla } [/code] now … Re: Question about reversal and array storage for Palindrome Programming Software Development by Ancient Dragon do you have to reverse just the words? "Hello World" becomes "World Hello" or reverse all the letters? Reversing the letters is easy -- reversing words becomes a little more complex. As I mentioned in my previous post, you need to create a second string and copy the characters to it in reverse order -- create a loop that … Re: Question about reversal and array storage for Palindrome Programming Software Development by xerA [quote=Ancient Dragon;271875]do you have to reverse just the words? "Hello World" becomes "World Hello" or reverse all the letters? Reversing the letters is easy -- reversing words becomes a little more complex.[/quote] the letters. The letters have to be reversed so that it can be compared to the normal line. Re: Question about reversal and array storage for Palindrome Programming Software Development by Ancient Dragon [QUOTE=xerA;271878]the letters. The letters have to be reversed so that it can be compared to the normal line.[/QUOTE] Good -- that simplifies the program. See my previous post. The rest you will have to figure out because I don't want to write your program for you. Re: String Reversal without using indexing. Programming Software Development by ~s.o.s~ The above method for gettign the string from the user wont work and would give an run time error since the user input is stored in a character ptr for whom no memory has been allocated. Better use [code] [COLOR=#339933]#include<stdio.h>[/COLOR] [COLOR=#339933]#include<string.h> [/COLOR][COLOR=#993333]char[/COLOR] *strrev[… Re: String Reversal without using indexing. Programming Software Development by risby Untested, unformatted, uses deprecated functions like gets and doesn't allocate space for its data. Should be removed. Re: String Reversal without using indexing. Programming Software Development by ~s.o.s~ Thats the reason i posted the updated version which works and uses safe functions like fgets(). :mrgreen: Re: Byte Reversal Programming Software Development by gerard4143 If your doing a straight rev of bytes why are you stripping the first bit [ICODE] x = (x & 0x7FFFFFFF ); [/ICODE] Re: Byte Reversal Programming Software Development by gerard4143 Also, you might get more info from your print statements if you use the hex format character %x - like [ICODE] printf("x is %x\n", x); [/ICODE] Re: Byte Reversal Programming Software Development by codeguru_2009 At line 12 you are working on one byte, means interchanging last 2 nibbles. so after line 12 executes x becomes 0x00000040. X has lost its original value. You cannot operate on x in two statements. This can be done if you take other variable. But for x you need something like this [QUOTE][CODE] x = x << 24 | (x & 0xff00) << 8 | (x …