Click here to Skip to main content
Click here to Skip to main content
Alternative Article

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

, 16 Dec 2012
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"

Code

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 floats 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)

Share

About the Author

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

Comments and Discussions

 
GeneralThanks for this ... PinmemberHugh Glover28-Jun-13 0:00 
QuestionCode is GPL PinmemberChase Rayfield22-Jan-13 8:02 
AnswerRe: Code is GPL PinmemberAlan Churchill3-Mar-13 11:46 
GeneralMy vote of 1 PinmvpPaulo Zemek17-Dec-12 9:37 
GeneralRe: My vote of 1 PinmemberAlan Churchill3-Mar-13 11:48 
QuestionVAX? PinmemberPIEBALDconsult17-Dec-12 3:46 
SuggestionWould be nice with a download link... Pinmemberkisko11-Dec-12 21:44 
GeneralRe: Would be nice with a download link... PinmemberAlan Churchill16-Dec-12 19:58 
QuestionDownload Link Missing PinmemberTarek K. Mahfouz18-Nov-12 19:43 
QuestionDownload link PinmemberNgaima Sandiman12-Nov-12 20:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

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