REM Calculates large terabyte hexidecimal values.
REM $INCLUDE: 'format.bi'
DIM x AS DOUBLE
DIM z1 AS DOUBLE
DIM z2 AS DOUBLE
DIM z3 AS DOUBLE
DIM z4 AS DOUBLE
CLS
' maximum extended fat32 long = ffff ffff ffff ffffh
x = 512
GOSUB calc
x = 768
GOSUB calc
x = 896
GOSUB calc
x = 960
GOSUB calc
x = 1024
GOSUB calc
END
calc:
PRINT x; "terabyte extended"
x = x * 1024 ^ 4 - 1 ' <x> TB.
PRINT "fat32="; FormatD$(x, "#,##0;;"); "=hex:";
z1 = x - INT(x / &H10000) * &H10000 ' 0000 0000 0000 ffff
x = x - z1: x = x / &H10000
z2 = x - INT(x / &H10000) * &H10000 ' 0000 0000 ffff 0000
x = x - z2: x = x / &H10000
z3 = x - INT(x / &H10000) * &H10000 ' 0000 ffff 0000 0000
x = x - z3: x = x / &H10000
z4 = x                              ' ffff 0000 0000 0000
x = x - z4: x = x / &H10000 ' x should now equal zero.
PRINT RIGHT$("0000" + HEX$(z4), 4);
PRINT RIGHT$("0000" + HEX$(z3), 4); " ";
PRINT RIGHT$("0000" + HEX$(z2), 4);
PRINT RIGHT$("0000" + HEX$(z1), 4); " ";
x = 0
x = z1 + z2 * &H10000 + z3 * &H10000 * &H10000 + z4 * &H10000 * &H10000 * &H10000
PRINT "("; FormatD$(x, "#,##0;;"); ")"' should equal original definition
RETURN

