473,387 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Little Endian & Binary

Hi.

How do I display a binary data that is formatted in little endian in Visual C++ 6?
Can I just display it as per normal or is there an additional code to use to read and display it?
Jan 31 '07 #1
4 4291
RedSon
5,000 Expert 4TB
Hi.

How do I display a binary data that is formatted in little endian in Visual C++ 6?
Can I just display it as per normal or is there an additional code to use to read and display it?
What are you trying to do? You can display binary data that is formatted in little or big endian using a normal hex editor or binary reader like TextPad. If you are trying to read in serialized data that is in little endian, you should be able to just use the standard binary serialization library to read in that data.

In other words, the short answer to "How do I display binary data in little endian?" is "by double clicking on it". The long answer requires more specification on your part.
Jan 31 '07 #2
The hex display of the data is like this: 2E FA CC F6 9F FC... So since it is little endian, do I have to change the data to FA 2E F6 CC FC 9F?
And Im supposed to divide the data by two. Do I just divide 2E by two or FA 2E by two?

I just cant figure this out. Can someone help me?
Feb 1 '07 #3
RedSon
5,000 Expert 4TB
The hex display of the data is like this: 2E FA CC F6 9F FC... So since it is little endian, do I have to change the data to FA 2E F6 CC FC 9F?
And Im supposed to divide the data by two. Do I just divide 2E by two or FA 2E by two?

I just cant figure this out. Can someone help me?
Again, I don't know how to help you unless you can be more specific about your problem. Yes its true that little endian means that the data is stored "little end first" but if you want to display it in a hex editor just open your favorite hex editor and then open the file, its as simple as that. If you are trying to read in the binary data into an application then you could open a file stream and read in some bytes, then swap the low order bits with the hi order ones. Or you could use a library to open a binary stream reader and get it that way. Or you could send the raw data to a printer because after all that is a display device.

You need to be more specific.
Feb 1 '07 #4
Hi. Sorry for not being specific. Im trying to do the second one. The one on swapping the low order bytes with the high order ones. Im using VC6.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. ifstream file;
  6. ofstream newFile;
  7.  
  8. int main ()
  9. {
  10.     int j = 0, i;
  11.     char array[10], chg[5];
  12.  
  13.     file.open ("s0455_re.dat", ios::in|ios::binary);
  14.     newFile.open ("NewFile.bin", ios::out|ios::binary);
  15.  
  16.     if (file.is_open())
  17.     {
  18.         cout << "Able to open file!" << endl;
  19.  
  20.         if (newFile.is_open())
  21.         {
  22.             cout << "Able to open new file!" << endl;
  23.  
  24.             while (j < 10)    // loop while extraction from file is possible
  25.             {    
  26.                 array[j] = file.get();       // get character from file
  27.                 j++;
  28.             }
  29.  
  30.             j = 0;
  31.  
  32.             for (i=0; i<5; i++)        // i is half of j
  33.             {
  34.                 chg[i] = ((int) array[j+1] << 8) + array[j];        // swap position
  35.                 newFile << chg[i];
  36.  
  37.                 j = j + 2;
  38.             }
  39.             newFile.close();
  40.         }
  41.  
  42.         else
  43.             cout << "Unable to open new file.";
  44.  
  45.         file.close();
  46.     }
  47.     else
  48.         cout << "Unable to open file";
  49.  
  50.     return 0;
  51. }    
In the swap position, Im trying to swap the position of the first byte with the second one, the third with the forth and so on. But when i write on the newFile, its only the first, third etc bytes are written. What should i do for the swap position?
Thanks for your patience.
Feb 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: hicham | last post by:
Hi, I am looking for help, i would like to know how can i use the endian.h and config.h to convert compiled files under solaris from BIG-ENDIAN to compiled files LITTLE-ENDIAN. I am working...
8
by: Perception | last post by:
Hello all, If I have a C-like data structure such that struct Data { int a; //16-bit value char; //3 ASCII characters int b; //32-bit value int c; //24-bit value }
5
by: glueless | last post by:
I have to read files from UNIX systems on my PC. The problem is that these binary files are in big endian and I need to convert them. I saw that there are functions ntohl for my visual C++ (4.0),...
11
by: Steve | last post by:
Hi, i know this is an old question (sorry) but its a different problem, i need to write a binary file as follows 00000011 00000000 00000000 00000101 00000000 11111111
3
by: Eric J.Hu | last post by:
Hi, Such as I have following bitmap structure and assigned value: struct bm { char high2bits:2; char mid4bits:4; char low2bits:2; }; bm.high2bits = 3;
2
by: bhatia | last post by:
Hello all, If I have a C-like data structure such that struct Data { int a; //16-bit value char; //3 ASCII characters int b; //32-bit value int c; //24-bit value }
5
by: mohamed.alam78 | last post by:
Greetings, How does one find the format of a binary file to be in Little Endian or big Endian before we start reading the file. Thanks
13
by: junky_fellow | last post by:
Hi guys, I need to convert a big endian integer to little endian integer. (the integer is 4 bytes in size on my implementation). I came up with the following code. I need your comments on...
23
by: Niranjan | last post by:
I have this program : void main() { int i=1; if((*(char*)&i)==1) printf("The machine is little endian."); else printf("The machine is big endian."); }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.