question for the guru's about data types 
Author Message
 question for the guru's about data types

  I am loading a file containing 14 4-byte numbers.
 A hex-dump of the file looks like this:

 0000 000C  0000 000C  0000 000C  0000 000C
 0000 091A  0000 1025  0000 0140  0000 0014
 0000 091A  0000 09F3  0000 1AF3  0000 1A0C
 0000 1025  0000 1BCE

 I know above numbers represent these numbers:
0,0,0,0,52,106,17,3,52,58,68,80,106,279

What format are these numbers and what would a C snippet of code look like
to load these numbers from disk into an array of INT's or FLOATS?

Any help would be appreciated.
Thanks, Ken



Sun, 03 Oct 1999 03:00:00 GMT  
 question for the guru's about data types

Quote:

>   I am loading a file containing 14 4-byte numbers.
>  A hex-dump of the file looks like this:

>  0000 000C  0000 000C  0000 000C  0000 000C
>  0000 091A  0000 1025  0000 0140  0000 0014
>  0000 091A  0000 09F3  0000 1AF3  0000 1A0C
>  0000 1025  0000 1BCE

>  I know above numbers represent these numbers:
> 0,0,0,0,52,106,17,3,52,58,68,80,106,279

Are you quite sure? It must be a pretty odd computer which represents
0 as 0x0000000C; this would usually be either 12 or some large number
(depending on the endianness of your machine, and also whether these
numbers are signed). It's possible they're in some kind of floating
point format, I suppose, but even then 0.0 usually comes out as all
zeroes.

Quote:
> What format are these numbers and what would a C snippet of code look like
> to load these numbers from disk into an array of INT's or FLOATS?

I have no idea what format these numbers are in. If you have an
array of numbers on the disk which are in the correct format for
your computer, you can load them with

int x[14];
FILE *fileptr = fopen("filename","rb");
fread(x,sizeof(int),14,fileptr);

If they're not in the correct form (which I strongly suspect), you'll
have to munge them around a bit.

-Edwin



Mon, 04 Oct 1999 03:00:00 GMT  
 question for the guru's about data types

Quote:

>   I am loading a file containing 14 4-byte numbers.
>  A hex-dump of the file looks like this:

>  0000 000C  0000 000C  0000 000C  0000 000C
>  0000 091A  0000 1025  0000 0140  0000 0014
>  0000 091A  0000 09F3  0000 1AF3  0000 1A0C
>  0000 1025  0000 1BCE

>  I know above numbers represent these numbers:
> 0,0,0,0,52,106,17,3,52,58,68,80,106,279

> What format are these numbers and what would a C snippet of code look like
> to load these numbers from disk into an array of INT's or FLOATS?

You can either read the hexadecimal numbers as text and convert it
yourself:
  char text[5];
  fscanf( file, " %4s", text );
  /* do your own conversion */

The only conversion functions that standard C offers for converrting
hexadecimal string to decimal integers is "sprintf()". Therefore you
might choose the following method right away.

You can let "fscanf()" do the conversion for you:
  int number;
  fscanf( file, " %x", number );
  /* no more conversion required */

Stephan



Mon, 04 Oct 1999 03:00:00 GMT  
 question for the guru's about data types

Quote:

> Bits 0 and 1 are likely candidates for (odd) parity bits,
> since 0 is represented by 0000 000C (or 00...011 binary).

Oops! Replace that with                   00..1100 binary.
and replace 'Bits 0 & 1' with 'Bits 2 & 3'.
--

CMG Telecommunications & Utilities B.V.
Division Advanced Technology                      Tel: +31 30 23 39 300
P.O.Box 8038                                      Fax: +31 30 23 39 495
3503 RA Utrecht, The Netherlands


Mon, 11 Oct 1999 03:00:00 GMT  
 question for the guru's about data types

Quote:


> >   I am loading a file containing 14 4-byte numbers.
> >  A hex-dump of the file looks like this:

> >  0000 000C  0000 000C  0000 000C  0000 000C
> >  0000 091A  0000 1025  0000 0140  0000 0014
> >  0000 091A  0000 09F3  0000 1AF3  0000 1A0C
> >  0000 1025  0000 1BCE

> >  I know above numbers represent these numbers:
> > 0,0,0,0,52,106,17,3,52,58,68,80,106,279

> Are you quite sure? It must be a pretty odd computer which represents
> 0 as 0x0000000C; this would usually be either 12 or some large number
> (depending on the endianness of your machine, and also whether these
> numbers are signed). It's possible they're in some kind of floating
> point format, I suppose, but even then 0.0 usually comes out as all
> zeroes.

I think you misunderstood.
  0:  0000 000C
  0:  0000 000C
  0:  0000 000C
  0:  0000 000C
 52:  0000 091A
106:  0000 1025
 17:  0000 0140
  3:  0000 0014
 52:  0000 091A
 58:  0000 09F3
 68:  0000 1AF3
 80:  0000 1A0C
106:  0000 1025
279:  0000 1BCE

This is quite a weird format.

Perhaps it's some sort of Hamming code.
A Hamming code is a code where several parity bits are added in
interesting places (N parity bits for 2^N data bits) to be able to
detect and correct a single bit error.
Did you get these data from a serial link or something else error
prone, like a barcode reader?

A parity bit's value is set to a value that makes the total number
of 1's in the number (incl. parity bit) even ("Even parity")
or odd ("Odd parity").

In a Hamming code, every parity bit checks its own group of bits,
e.g.:
1st parity bit checks 0x0x0x0x0x0x0x0x
2nd parity bit checks 00xx00xx00xx00xx
3rd parity bit checks 0000xxxx0000xxxx
etc.

I don't remember what the best place for the parity bits was, though.
Bits 0 and 1 are likely candidates for (odd) parity bits,
since 0 is represented by 0000 000C (or 00...011 binary).
Bits 0 and 1 bring the total nr. of 1's in there respective areas
to an odd number (being 1).
I THINK the other parity bits are not set to 1 because they each
check on one of the first parity bits, but I'm not at all sure
about that.

You probably have 16 data bits, 4 parity bits and 4 unused bits.

Can you get the values for 1, 2, 3, 4 etc. and for e.g. 254, 255, 256,
65534, 65535, and all powers of 2?
I'll dig up ye ol' dig'tal tech books at home and puzzle on this
for a wee while...

Of course, none of this is on-topic for comp.lang.c. :-(
--

CMG Telecommunications & Utilities B.V.
Division Advanced Technology                      Tel: +31 30 23 39 300
P.O.Box 8038                                      Fax: +31 30 23 39 495
3503 RA Utrecht, The Netherlands



Mon, 11 Oct 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. This is a biztalk question but probably an easy question for you C# guru's

2. ATL data type for VB Object data Type

3. SQL timestamp data type - correspondency with c++ data type

4. Mapping ADO data types with C++ data types

5. Question for the Guru's

6. A few questions for the real guru's

7. Guru's Question

8. A few questions for the real guru's

9. OLE data types / standard data types

10. How to COM's VARIANT* or SAFEARRAY data type in C#

11. Member Variables' data type

12. to all the 'gurus'....

 

 
Powered by phpBB® Forum Software