ID3TagEd icon - 1314 bytes

UnitConv

Bin to hex conversion window


The bin to hex conversion window

bin-oct-hex-dec conversion
dialogueThe layout of this window needs little comment. There are four fields, into any one of which you can type the number, in appropriate format, and the converted values are shown in the other fields. Only the digits/symbols which are used to represent a particular format may be typed into the corresponding field. The range of values that are legal correspond to those of a four byte (32 bit) word representing an unsigned integer. Values falling outwith this range are trapped, and an error message is raised.

You may also enter negative decimal numbers. For example, entering -1 into the decimal field will lead to the hexadecimal field showing FFFFFFFF. The range of negative decimal numbers that can be used is -1 to -2147483648, corresponding to hex values of &FFFFFFFF to &80000000.


Alternative method of entering binary numbers

bin-oct-hex-dec conversion
dialogueClicking on the 'toggle' icon in the title bar will cause the window to extend. This shows another display of the number in binary format. Clicking SELECT on a digit will toggle it from 0 to 1 or 1 to 0, depending on the original state. The change will immediately be mirrored in the four fields in the top of the window. This makes it easier to calculate numbers corresponding to particular bits being set/unset. The numbers underneath the display show the position of each bit (0 is the least significant, and 31 is the most significant bit) to enable particular bits to be found more easily. When clicking on a digit, ensure the click is in the centre of the digit - clicking between two digits will result in uncertainty over which digit will toggle.

At the foot of the window are some buttons to help in the manipulation of bit fields.

Clear does just that - it will set all the values to 0.

Invert will change every 0 bit to a 1 and every set bit (1) to a zero. This may be useful when setting up masks to be used to set or clear particular bits, leaving the others in the word unchanged.

Shift has two bump arrows to shift the bits left or right. Simply clicking on the bump arrows will shift by one bit position each time. Clicking with SHIFT held down will move by four bit positions each time. Clicking with CTRL held down will move by eight bit positions, while SHIFT and CTRL held down together will move by sixteen bit positions.

Conversion settings

Clicking SELECT on the Settings... button will open the bin-oct-hex-dec settings dialogue. This allows the way the results are displayed to be specified.

bin-oct-hex-dec settings dialogue

Show all leading zeros

If this is selected then the converted values (other than decimal) are shown in the full four byte, 32 bit, representation with all leading zeros, as shown in the figure below. Note that decimal numbers are never shown with leading zeros.

bin-oct-hex-dec all zeros

Strip leading zeros

If this is selected then the converted values are shown with all leading zeros stripped, as shown in the figure below.

bin-oct-hex-dec leading zeros stripped

Strip leading zero bytes

If this is selected then the converted values (other than decimal) are shown as the smallest number of complete bytes (1, 2, 3 or 4) to represent the number, with leading zeros as necessary, as shown in the figure below.

bin-oct-hex-dec complete bytes

Show decimal as signed integer

In computer applications the top bit of the binary representation of a number may be interpreted as denoting a negative number. In C, for example, there are signed and unsigned integer types. BBC Basic, on the other hand, always uses signed integers. This option, when ticked, will display decimal numbers as negative values if the top bit (bit 31) is set. The two images below show the difference when the same hexadecimal number is converted with this option off and then on.

hex-dec unsigned conversion     hex-dec unsigned conversion

For a four byte, 32 bit, integer, an unsigned integer can take values, in decimal, of 0 to +4294967295, while a signed integer can take values of −2147483648 to +2147483647.

Shift bits wraps around

Under normal operation when shifting bits, bits which 'fall off' the end of the word are lost, and new bits coming in at the other end are all 0. Under certain circumstances 'wrapping round' may be the required option. In this case, the bits (either 0 or 1) that fall out of the end reappear at the other end. If this option is ticked, then wrap around becomes the normal behaviour.

At the bottom of the dialogue are three buttons.

Set will apply the settings immediately, but the settings will be forgotten once UnitConv is quit.

Save will apply the settings immediately, and also save the settings so UnitConv will use the same ones when it is next started.

Cancel will simply close the window without making any changes.


Larr.gif - 145
bytes Unit conversion window   |   Index  |   Image size calculator Rarr.gif - 141 bytes

These pages are best viewed in a CSS compliant browser. For RISC OS, Netsurf would be the browser of choice.

UnitConv is © Chris Johnson, 2012
Email:chris@chris-johnson.org.uk