3. Value Notations

JTT supports three value notations (representations): decimal (dec), binary (bin) and hexadecimal (hex). The latter two are elaborated upon in this section, and decimal is just mentioned (since it is expected that you know how to use this).

Although JTT usually does not mind which you use, you must say which you are using by affixing its symbol, if any, with the data. The table below shows the notations and identifiers. These symbols are used through the Manual to avoid ambiguity.

Please Note
When entering values in any notation, it is not necessary to have a certain number of digits. E.g., (decimal) 00012 can be written 12. However, there are limits to the value that can be entered. JTT is predominantly 16-bit, so for each value entered, the minimum is 0 and the maximum 2^16 (i.e. a range of 0 to 65535 (decimal), $0 to $1111 1111 1111 1111 (binary) or 0x0 to 0xffff (hex).
Sometimes, for clarity, large decimal values are separated by series of commas, and binary and hex values by spaces. However, it should be noted that they should be typed without such spacers, as if a fluent value, or the result will be a syntax error.
Of course, decimal 00012 equals 12, whilst 12000 does not, since trailing digits denote ever increasing values. In the same way, remember that binary $001 equals $1 but not $100, and hex 0x0f equals 0xf but not 0xf0, for example.

Notation Template Example Details
Decimal 123 This is the default, no symbol needed.
Binary $ $01011 The dollar sign precedes binary values.
Hex 0x 0xff '0x' precedes hex values. It is an old convention, used in many languages.

3.1 Binary (Bin)

Binary values are base-2. So, whilst decimal is base-10 (after 9, digit is added, lowest digit reset to 0), in binary, after �1� a digit is added and the lowest reset to 0. The table below gives examples. Note that each time a binary digit (called a 'bit') is added, the corresponding value doubles.

Dec. Bin. Dec. Bin. Dec. Bin.
0 $0 15 $1111 255 $1111 1111
1 $1 16 $1 0000 512 $10 0000 0000
2 $10 31 $1 1111 1024 $100 0000 0000
3 $11 32 $10 0000 2048 $1000 0000 0000
6 $110 63 $11 1111 4096 $1 0000 0000 0000
7 $111 64 $100 0000 8192 $10 0000 0000 0000
8 $1000 127 $111 1111 65535 $1111 1111 1111 1111

3.2 Hexadecimal (Hex)

Hex values are base-16. Per digit, 0 to 9 are as with decimal. However, 10 becomes A, 11 becomes B and so on up to 15, which becomes F. After that, a new digit is added. Hex is a shorthand for binary. Both are easily compatible, and hex is four times more compact (due to the fact that each digit holds 2^4 times the amount). Hex is widely used in HTML and sometimes in heavily mathematical programs in other languages although supported by most programming languages. The table below gives some examples of its use and the conversion between decimal and hex.

Please Note
Hex letters are not case sensitive. However, lower-case is conventional.

Dec. Hex. Dec. Hex.
0 0x0 16 0x10
1 0x1 17 0x11
9 0x9 18 0x12
10 0xa 255 0xff
11 0xb 256 0x1 00
12 0xc 4095 0xfff
13 0xd 4096 0x10 00
14 0xe 65534 0xfffe
15 0xf 65535 0xffff

3.3 Converting between notations

Here are some examples of associated decimal, binary and hex values, which are within JTT's range. You may use them for reference and study them to f familiarise yourself with the similarities of each notation. Although not used much here, it is useful generally to know that a 16-bit value is known as a 'Word', and a 32-bit value a 'DWord', or double word.

Note that binary doubles with each affixed digit, and hex multiplies by 16. Hence, for example, 0x10=1^16=16, and 0x100=2^16=256.

Dec. Bin. Hex. Dec. Bin. Hex.
0 $0 0x0 63 $11111 0x3f
1 $1 0x1 64 $100000 0x40
2 $10 0x2 255 $1111111 0xff
7 $111 0x7 256 $10000000 0x100
8 $1000 0x8 4095 $111111111111 0x3ff
15 $1111 0xf 8191 $1111111111111 0x7ff
16 $10000 0x10 16384 $11111111111111 0xfff
31 $11111 0x1f 32767 $111111111111111 0x7fff
32 $10000 0x20 65535 $1111111111111111 0xffff

3.4 Converting Binary values to Hexadecimal

Converting between binary and hex is easy. To convert binary to hex:

  1. Split up the binary value into fours from the right. If there are leftover bits on the left, prefix 0s to make up a group of four.
  2. Each group will be between 0 and 15, so can be converted to a single hex letter. Do this for each group.
  3. Place the letters created together in order to give the total hex value.

See the table below for an example.

Binary Value: $11010111011110
Step 1: Binary Group: 0011 0101 1101 1110
Step 2: Equivalent Hex: 3 5 d e
Step 3: Hex Value: 0x35de

3.5 Converting Hexadecimal values to Binary

To convert hex to binary:

  1. Split up the hexadecimal value into separate, single digits.
  2. For each digit, work out the corresponding binary value, which will be between $0000 and $1111. If the value has less than four digits, prefix 0s to make up.
  3. Place the groups of four bits in order, to give the total binary value.

See the table below for an example.

Hex Value: 0x35de
Step 1: Hex group: 3 5 d e
Step 2: Equivalent Binary: 0011 0101 1101 1110
Step 3: Binary Value: $11010111011110

Addresses or registers that are coupled to be used with 32-bit values must be juxtaposed from an initial even address. That is, an even address (i.e. an address whose value is even) must be coupled with an odd address, and an even register must be coupled with an odd register. This syntax is important (and indeed necessary) in assembly languages, as it automatically rules out illegal memory values to a large extent.
3.6 Using 32-bit Values

Please Note
32-bit values are also called 'double' values. In JTT, the technique can be applied to data memory and registers.

It was said earlier that JTT is predominantly (but not wholly) 16-bit. This is because JTT can computing 32-bit numbers by pairing consecutive data memory addresses, and treating each pair as one value. Let�s take an example. Say memory address 'A' contains the value (decimal) 15, and address 'B' the value (decimal) 5. Value 'AB' is the result. This is illustrated and elaborated in the table below.

Addr Dec. Bin. Hex.
A 15 $0000000000001111 0xf
B 5 $0000000000000101 0x5
AB 1,966,053 $0000 0000 0000 1111 0000 0000 0000 0101 0xf005

You should note that, in the 16-bit to 32-bit conversion (i.e. both Words and DWords), values are treated as binary and ALL 16 bits are taken into account. These two values are then juxtaposed together to make the 32-bit value. As a result, (decimal) 15+5 is not 20 as you would expect. Instead, it is 1,966,053.

When dealing with 32-bit numbers, the number range obviously change. The range of acceptable values (excluding in twos-complement - see Section 3.7) are shown in the table below. The maximum values are split into groups for readability.

Notation Min. Maximum Range
Decimal 0 4,294,967,295
Binary $0 $1111 1111 1111 1111 1111 1111 1111 1111
Hex. 0x0 0xffff ffff

3.7 Using Twos Complement (2s-comp)

Please Note
Those not at all familiar with the basics of twos complement mathematics are advised to skip the twos-complement part of this section until they are more familiar with JTT.

The following operations can also be applied to 32-bit numbers (i.e. DWords).

You will no doubt have noticed that all values that JTT appears to support are positive. However, this is not strictly the case. To use negative values, you must treat them as 2s-comp values.

With negative numbers, the leftmost bit of the 16 bits is used as the 'sign' bit. This is set to 0 if the value is positive, or 1 if the value is negative. Thus, the maximum range of values in 2s-comp is 2^15, or (decimal 32,767 or hex 0x7fff). The whole range is not lost, however, because when the sign bit is set, there is a maximum negative range of (-2^15)+1, or (decimal) -32,768. One is deducted from the negative total to take into account zero, midway up the range.

To convert a binary value between positive and negative, the following two- point rule is employed:

  1. NOT the binary value (i.e. convert each 0 to 1 and vice versa).
  2. Add one to the total.

It should be noted that the Zero and Negative flags are changed accordingly, and tell you whether the number is positive, negative or zero. The following table clarifies these points:

Dec. Binary Dec. Binary
0 $0000 0000 0000 0000 -0 $N/A
1 $0000 0000 0000 0001 -1 $1111 1111 1111 1111
2 $0000 0000 0000 0010 -2 $1111 1111 1111 1110
3 $0000 0000 0000 0011 -3 $1111 1111 1111 1101
4 $0000 0000 0000 0100 -4 $1111 1111 1111 1100
... ... ... ...
65532 $1111 1111 1111 1100 -65532 $0000 0000 0000 0100
65533 $1111 1111 1111 1101 -65533 $0000 0000 0000 0011
65534 $1111 1111 1111 1110 -65534 $0000 0000 0000 0010
65535 $1111 1111 1111 1111 -65535 $0000 0000 0000 0001

Each positive value (e.g. (decimal) 40) therefore has its relative negative counterpart (e.g. (decimal) -40), which can be reached by the same two-point rule.

Consider the rule. It can be seen in the table above that every negative number is the logical opposite (NOT) of its previous positive counterpart. For example, the binary representation of -4 is the NOT of +3, and -65534 is the NOT of +65533. Notice also that there are negative zero is not catered for, because it is addressed as positive zero. Therefore, -65535 minus 1 = +0.

You can decide whether to treat a 32-bit value as 2s-comp or not within your JTT program by using or ignoring these protocols (and using your brain) accordingly. JTT itself is not capable of distinguishing between positive and negative values, and care should be taken to treat a value in the correct way (usually be employing use of the negative flag).

Please Note
Although JTT does not directly aware of the use of 2s-comp, flags 4-7 of the Status Word do cater for it indirectly, by assuming that the last result was to be used in a twos-complement arrangement by the user.
Out of interest, another way of performing 2s-complement is to decrement the value by 1 before performing logical-OR on each bit.

Go to next chapter Go to top of page Go to Contents Page Go to HomePage E-mail the author
Hosted by www.Geocities.ws

1