12,821,315 members (40,652 online)
Alternative Article
Add your own
alternative version

#### Stats

16.1K views
124 downloads
9 bookmarked
Posted 12 Nov 2012

# Transform between IEEE, IBM or VAX floating point number formats and bytes expressions

, 16 Dec 2012 CPOL
 Rate this:
Please Sign up or sign in to vote.
This is an alternative for "Transform between IEEE, IBM or VAX floating point number formats and bytes expressions"

Download HERE

## Introduction

John Hou's work, Transform between IEEE, IBM, and VAX floating point numbers, was originally written in C++. I took John's work, and converted it to C# 4.0. This code helps with converting IBM floats to IEEE floats and vice-versa. It also includes transformations for VAX floats to IEEE floats.

This is a C# version of John Hou's wonderful work. Tangible software did the initial C++ to C# conversion, which I then cleaned up, fixed missing areas, and then wrapped the engine to make it easier to work with for .NET developers.

## Background

John Hou's work is documented here.

http://www.codeproject.com/Articles/12363/Transform-between-IEEE-IBM-or-VAX-floating-point-n?fid=236108&df=90&mpp=10&noise=1&prof=True&sort=Position&view=Expanded&spc=None&fr=1#xx0xx

## Using the code

The solution included here has a test project illustrating a simple IBM float conversion. Not every aspect of the code conversion was tested since the immediaten eed was IBM float support. Others are welcome to work on the VAX or IEEE parts. All code is in C#.

The main class library is Converter. It can be called as:

```Converter c =new Converter();
byte[] bytes = new byte[] { 0x00, 0x00, 0x00, 0x80, 0x31, 0x93, 0x60, 0x48 };
double d = c.ConvertBytesToDouble(Platform.IbmFloat, bytes);

Console.WriteLine("Correct return value should be: " + 1620259200);
Console.WriteLine("Return Value:                   " + d);
Console.WriteLine();
Console.WriteLine("Press any key to continue...");
Console.Read();```

Additional methods available off of the Converter class are:

• `ConvertDoublesToBytes` - Converts a `double` value to `byte` array
• `ConvertSingleToBytes` - Converts single `float`s to `byte` array

All of the methods will take a `Platform` enum indicating the source of the origination bytes or doubles.

## History

2012-11-12  Initial version.

## License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

## About the Author

 Software Developer (Senior) Savian United States
SAS, Microsoft developer/consultant.

 Pro

## Comments and Discussions

 First Prev Next
 Issue converting small float values? Member 121839758-Jan-16 9:58 Member 12183975 8-Jan-16 9:58
 Fixed link Alan Churchill12-Feb-15 11:28 Alan Churchill 12-Feb-15 11:28
 Thanks for this ... Hugh Glover28-Jun-13 1:00 Hugh Glover 28-Jun-13 1:00
 Code is GPL Chase Rayfield22-Jan-13 9:02 Chase Rayfield 22-Jan-13 9:02
 Re: Code is GPL Alan Churchill3-Mar-13 12:46 Alan Churchill 3-Mar-13 12:46
 Re: Code is GPL Chase Rayfield16-Oct-14 12:13 Chase Rayfield 16-Oct-14 12:13
 My vote of 1 Paulo Zemek17-Dec-12 10:37 Paulo Zemek 17-Dec-12 10:37
 Re: My vote of 1 Alan Churchill3-Mar-13 12:48 Alan Churchill 3-Mar-13 12:48
 VAX? PIEBALDconsult17-Dec-12 4:46 PIEBALDconsult 17-Dec-12 4:46
 Would be nice with a download link... kisko11-Dec-12 22:44 kisko 11-Dec-12 22:44
 Re: Would be nice with a download link... Alan Churchill16-Dec-12 20:58 Alan Churchill 16-Dec-12 20:58
 Download Link Missing Tarek K. Mahfouz18-Nov-12 20:43 Tarek K. Mahfouz 18-Nov-12 20:43
 Download link Ngaima Sandiman12-Nov-12 21:45 Ngaima Sandiman 12-Nov-12 21:45
 Where is the download link?Jesus Is Lord
 Last Visit: 31-Dec-99 19:00     Last Update: 26-Mar-17 10:13 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 17 Dec 2012
Article Copyright 2012 by Alan Churchill
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid