@node AppF APPENDIX F: Hexadecimal values F.1 Introduction Hexadecimal (or 'hex' for short) is basically just a different way of representing numbers. It is more convenient for the computer because of the way it works, and allows the user to specify a greater range of numbers using the same amount of digits. Hex values are used in the player commands, MIDI message editor, and the synth editor, so they're quite important in OctaMED. In the usual decimal system, a digit can be ten different values: 0, 1, 2, 3, 4, 5, 6, 7, 8 or 9. In the hex system, however, a digit may have sixteen values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E or F. The decimal numbers 10 - 15 are represented by the letters A to F: Decimal 10 = Hex A; 11 = B; 12 = C; 13 = D; 14 = E; 15 = F With two digits in a number, the decimal system can represent 10 x 10 = 100 different values. The hex system, however, can represent 16 x 16 = 256 values: well over twice the amount of the decimal system. (The lowest hex number is 00 = zero, and the highest is FF = 255 decimal). F.2 Converting between the two systems So although it feels strange to work in at first, it has its advantages. In a two digit hex number (e.g. 8A), the first digit represents multiples of 16. So, to convert a two-digit hex number to decimal: Decimal number = (Hex digit 1) x 16 + (hex digit 2) And to convert decimal to hex, divide the decimal number by 16. The quotient is hex digit 1, the remainder is hex digit 2. e.g. 1) Hex 8A -> decimal: Hex digit 1 = 8, hex digit 2 = A (10). Decimal number = (8 x 16) + 10 = 138. 2) Decimal 200 -> hex: 200 ÷ 16 = 12 remainder 8. Hex digit 1 = C (12), hex digit 2 = 8. So hex number = C8. Hex numbers are sometimes distinguished from decimal numbers by preceding hex with a $ sign. For example: $C8, $FF. F.3 Signed hexadecimal There is a further complication! With the advent of OctaMED Soundstudio, a significant number of player commands now have "signed" hex command levels. The sign of a number denotes whether the number is positive or negative: that is, the + and - signs. In hexadecimal, however, there are no - signs. So, negative numbers are represented by positive numbers (it will become clearer!). In signed hex, the numbers $00 - $7F are positive as usual: they represent the decimal numbers 0 - 127. However, the numbers $80 - $FF represent the decimal values -1 to -128: Decimal -1 = Hex $FF; -2 = $FE; -3 = $FD etc. Decimal -16 = Hex $F0; -17 = $EF; -18 = $EE etc. Decimal -126 = Hex $82; -127 = $81; -128 = $80 So to convert negative decimal numbers to signed hex numbers, first add 256 to the number, then convert to hex as above. e.g. Decimal -67 -> signed hex: -67 + 256 = 189. 189 ÷ 16 = 11 remainder 13. Hex digit 1 = 11 (B), hex digit 2 = 13 (D) So signed hex number = $BD. It's important to realise that a signed hex number looks exactly the same as a normal hex number. There is no way of telling whether $FC is 252 decimal or -4 decimal just by looking at it; it is the context that tells you whether the number is normal or signed. For example, in the context of player command 15 (set finetune), $FC would be interpreted as -4. In the context of player command 01 (slide pitch up), it would be 252. Hex numbers will crop up in many areas of computing, so if you've never worked with them before, it's a good idea to get used to them! @{" Contents " link "Main" 0} @endnode