byte swapping 32-bit float and weird od results


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users byte swapping 32-bit float and weird od results
# 1  
Old 05-18-2009
byte swapping 32-bit float and weird od results

I'm attempting to read a file that is composed of complex 32-bit floating point values on Solaris 10 that came from a 64-bit Red Hat computer.

When I first tried reading the file, it looked like there was a byte-swapping problem and after running the od command on the file Solaris and Red Hat computers, I saw that they were indeed swapped (every other byte). So, I wrote a little Java program that would swap every other byte and the result was the at the byte-level, the files were the same on both computers. The following is the result of running 'od -x' on the file, showing the first 32-bits which represent the real portion of the first complex number:

f8a6 be03 cd76 bc99

What's weird is that when I run 'od -f' on both computers to see the 32-bit floating point value, I get different results! On the Red Hat computer I get: -1.288782e-01 and on the Solaris computer I get: -2.7055474e+34 Smilie. How can I have the same byte level file yet come up with completely different values when I try to print out the bytes as 32-bit floats?

This is really messing me up trying to write a C++ program to read this file on the Solaris computer. I'm getting the same value in my C++ code as what I see when I run 'od -f' on the Solaris computer. I've tried just about everything that I can think of and haven't been able to get past this.

Does anyone have any idea on what's going on with the od command between the Red Hat and Solaris computers? Any ideas on how to get my C++ code to give me the correct value for the 32-bit float?
# 2  
Old 05-20-2009
On the 64-bit platform, what format are the floating point numbers? Double precision (64-bit) IEEE 754 binary floating-point numbers? Single precision (32-bit) binary IEEE 754 floating-point numbers? Are they in standard IEEE 754 interchange format or some form of custom arithmetic format? Binary or decimal format?

In other words, first you need to figure out exactly what format was used to represent the floating points numbers.

If you provide more information we can probably help you.
# 3  
Old 05-20-2009
I never did figure out the od problem, but I was able to get the bytes swapped properly and everything is working good.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Which version of Windows Vista to install with a product key? 32-bit or 64-bit?

Hello everyone. I bought a dell laptop (XPS M1330) online which came without a hard drive. There is a Windows Vista Ultimate OEMAct sticker with product key at the bottom case. I checked dell website (here) for this model and it says this model supports both 32 and 64-bit version of Windows... (4 Replies)
Discussion started by: milhan
4 Replies

2. UNIX for Beginners Questions & Answers

Weird 'find' results

Hello and thanks in advance for any help anyone can offer me I'm trying to learn the find command and thought I was understanding it... Apparently I was wrong. I was doing compound searches and I started getting weird results with the -size test. I was trying to do a search on a 1G file owned by... (14 Replies)
Discussion started by: bodisha
14 Replies

3. Shell Programming and Scripting

Converting String To Integer/Float (weird case)

Hi guys, I'm new here. I have a problem at work. One of our scripts was eventually having a bug and only detected recently. Here's the issue and background: Bash Script which calls AWK script Awk script returns a string as per below (example):var1='00000-123'So, when we convert it, the... (18 Replies)
Discussion started by: sekfarok
18 Replies

4. UNIX for Dummies Questions & Answers

Byte to BIT conversion

I have a varchar column which contains the data at ‘bit' level.the data needs to be extract / transform at bit level and this will contain a Boolean value - 0/1. How can we handle using shell scripts At source level(DB2 Database) we have a column of length 250 char ie varchar(250) so each char... (2 Replies)
Discussion started by: Codesearcher
2 Replies

5. Programming

Weird timing results in C

I was running some timings in my code to see which of several functions was the best and I've been getting some odd results. Here's the code I'm using: static double time_loop(int (*foo)(int)) { clock_t start, end; int n = 0, i = 0; start = clock(); for (; i <= MAXN; i++) if... (6 Replies)
Discussion started by: CRGreathouse
6 Replies

6. Shell Programming and Scripting

Remove a byte(Last byte from the last line)

Hi All Can anyone please suggest me how to remove the last byte from a falt file .This is from the last line's last BYTE. Please suggest me something. Thank's and regards Vinay (1 Reply)
Discussion started by: vinayrao
1 Replies

7. Shell Programming and Scripting

Check if 2 files are identical byte-to-byte?

In my server migration requirement, I need to compare if one file on old server is exactly the same as the corresponding file on the new server. For diff and comm, the inputs need to be sorted. But I do not want to disturb the content of the file and need to find byte-to-byte match. Please... (4 Replies)
Discussion started by: krishmaths
4 Replies

8. Programming

math.h: float ceilf(float x)

Good morning, I'm testing the use of ceilf: /*Filename: str.c*/ #include <stdio.h> #include <math.h> int main (void) { float ceilf(float x); int dev=3, result=0; float tmp = 3.444f; printf("Result: %f\n",ceilf(tmp)); return 0; } (1 Reply)
Discussion started by: jonas.gabriel
1 Replies
Login or Register to Ask a Question