bitgui: A graphical explorer of the IEEE 754 floating point formats

Graphically edit the binary representation of floating point formats and analyze their values.
645 Downloads
Updated 30 Jan 2012

View License

This graphical tool displays an editable binary representation of the two floating point formats used in MATLAB, namely single and double.

For the selected number three displays are available:
* The value as formated by the MATLAB software
* The analysis of its segments: sign, mantissa and exponent
(The hidden bit is also taken into account)
* The binary representation of the number in the form of filled (active bit) or empty (inactive bit) boxes, accordingly coloured to distinguish the parts of the representation (sign, mantissa and exponent).

There are several ways to input the number to be displayed:
* From the commandline, using the arguments of the bitgui function:
>> bitgui(arguments)
Where arguments may be
- A string expression to be evaluated in order to calculate the value to be displayed
For this method the following syntax is also supported:
>> bitgui string expressions
- A floating point number which is directly displayed
- An unsigned integer which is displayed as that floating point number with the same bit represenation
* From within the GUI by:
- Clicking on the bits of the displayed binary representation.
You may also press and hold the left mouse buton to toggle multiple bits in a draw-like fashion.
- Providing a string expression to be evaluated in the base workspace.
Regardless the method, the value after each edit is also stored in the 'res' variable, stored in the base workspace.
NOTE: Using the stored value "res" allows the user to explore how the consecutive applications of an operator affects the binary representation.
Consider for example starting by evaluating "1" and consequently evaluate many times the expression:
* "res / 2"
* "res * 2"

The various representations of the value, as well as some accompanying data, are also available organised in a struct. The aforementioned struct, refered to as 'sval', may be returned by an invocation of the bitgui command at all times.

Implementation details:
To retrieve the binary representation file I/O is used. A file is created in the temporary folder (using the tempname function) and then unlinked/deleted. As a result, the user must have the permission to write within that folder. This was essential for retrieving the representation of single precision numbers (for doubles hex2num is provided, which is, however, not required by this program).

The program has been developed and tested under a linux distribution; it should however work on windows/Mac machines. Should the case be otherwise, feel free to inform me, or even better provide a patch to solve any bugs.

The supporting class, uint64plus:
This application uses uint64 addition. Since, however, MATLAB versions older than 7.11 do not support this operation, a new class named uint64plus was developed with the purpose of extending the uint64 class for the needs of this application. Mainly the functionality of addition and hexadecimal conversion has been implemented.
If you use MATLAB version 7.11 or newer, you may safely ignore/delete the uint64plus.m file.

Known bugs:
* The length of the text in the numeric expressions is fixed and does not shrink/expand as the gui is resized.
If you know of a way to calculate the number of characters that fit within a text box, please provide input.

Feel free to use or redistribute: the code is available under the BSD license and was developed mainly for teaching/demonstration purposes.

Cite As

Janis Kalofolias (2024). bitgui: A graphical explorer of the IEEE 754 floating point formats (https://www.mathworks.com/matlabcentral/fileexchange/33874-bitgui-a-graphical-explorer-of-the-ieee-754-floating-point-formats), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.4.0.0

Now within the returned structure, a record with the analysis of the various parts of the binary representation is also returned.
To demonstrate, try sval=bitgui;sval.parts

1.3.0.0

Made subnormal numbers more clearly distinguished by adding a check-box that is enabled for those numbers.
Exponent does not depict the binary representation, but the interpreted exponent, taking into account the case on subnormal numbers.

1.2.0.0

- Added support for older MATLAB versions (now should work on versions 2008b and newer)
- Added mouse-draw mode
- Added features interfacing with bitgui from command line for initialization and representation returning

1.0.0.0