HexCon

Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Utility

HexCon converts a hexadecimal number up to five digits long into its decimal equivalent. The user enters the hex string as a label and then inputs each digit position (a through e, representing positions 1 through 5) separately as numeric values; the program assigns the letters A–F the values 10–15 in lines 2 and 3 for the user to reference. Each positional value is multiplied by the appropriate power of 16 (1, 16, 256, 4096, or 65536) and the results are summed to produce the decimal output. The program loops via GO TO 4, allowing repeated conversions until the user types “no” in response to the continuation prompt.


Program Structure

The program is short and linear, organized into three logical phases: initialization, input/calculation, and output/loop control.

  1. Lines 2–3: Define numeric variables af as 10–15 (hex letter values) and print instructions.
  2. Lines 4–5: Accept the hex number as a display label string u$ and zero out working variables.
  3. Lines 30–51: Accept each hex digit position as a separate numeric INPUT and compute the weighted positional value.
  4. Lines 55–60: Sum all positional values and display the result.
  5. Lines 61–65: Prompt for another conversion, loop or stop.

Conversion Method

Rather than parsing a hex string character by character, the program asks the user to enter each digit as a number (0–15) individually. The positional weights are computed using explicit repeated multiplication rather than exponentiation:

PositionVariableMultiplierDecimal weight
a (least significant)As*11
bBt*1616
cCw*16*16256
dDx*16*16*164096
e (most significant)Ey*16*16*16*1665536

The maximum representable value is 0xFFFFF = 1,048,575, which fits within standard BASIC floating-point precision without issue.

Variable Naming Anomaly

The program uses both lowercase variables af (set in line 2 as the hex letter values 10–15) and uppercase variables AF (computed positional values in lines 31–55). On this platform, single-letter variable names are case-insensitive, meaning a and A refer to the same variable. This means the preloaded hex reference values (10–15) assigned in line 2 are silently overwritten by the positional calculations in lines 31–51. The hex letter reference values are effectively unusable after the first conversion digit is entered. The variables af from line 2 serve only as a visual reference printed on screen via the instruction text, not as programmatic lookups.

Input Design

The user enters the hex number twice: first as a free-form string u$ in line 4 (used purely for display in the output), then digit-by-digit as integers in lines 30–51. This separation means the display label and the computed digits are independent — a user could enter a mismatched label and digit sequence without any validation or error.

Line 5 resets variables s, t, u, v, w, x to zero at the start of each conversion, but note that u is reset here yet never used as a positional variable (the positions jump from t to w). Variable v and x are used as INPUT targets for positions d and the continuation response respectively; u remains unused as a numeric variable.

Notable Techniques and Bugs

  • Line 64 uses SAVE "HEX" LINE 0 to save the program; LINE 0 targets a non-existent line, which is a recognized technique on this platform.
  • The multiplication s*1 for the units position in line 31 is redundant but harmless.
  • There is no input validation: entering a value outside 0–15 for a hex digit, or a non-integer, will produce incorrect or erroneous results silently.
  • The loop returns to line 4 on a “yes” response, correctly re-prompting for the hex label string and resetting variables via line 5 before re-entering digit input.
  • The variable collision between af (line 2) and AF (lines 31–55) is the most significant bug in the program, though it does not affect the arithmetic output since the reference values are only cosmetic.

Image Gallery

Source Code

    2 LET a=10: LET b=11: LET c=12: LET d=13: LET e=14: LET f=15
    3 PRINT "This is a hexadecimal conversionroutine.";TAB 0;"Enter your hexadecimal number inthe following format: e d c b a."
    4 INPUT "the number";u$
    5 LET s=0: LET t=0: LET u=0: LET v=0: LET w=0: LET x=0
   30 INPUT "a";s
   31 LET A=s*1
   35 INPUT "b";t
   36 LET B=t*16
   40 INPUT "c";w
   41 LET C=w*16*16
   45 INPUT "d";x
   46 LET D=x*16*16*16
   50 INPUT "e";y
   51 LET E=y*16*16*16*16
   55 LET F=A+B+C+D+E
   59 PRINT "HEX     DECIMAL"
   60 PRINT u$;" = ";F
   61 INPUT "Do you wish another conversion?";TAB 0;"yes or no";v$
   62 IF v$="yes" THEN GO TO 4
   64 SAVE "HEX" LINE 0
   65 STOP 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.