MKI$: Difference between revisions
Jump to navigation
Jump to search
Code by Ted Weissgerber
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "The MKI$ function encodes an INTEGER numerical value into a 2-byte ASCII STRING value. {{PageSyntax}} : {{Parameter|result$}} = MKI$({{Parameter|integerVariableOrLiteral%}}) {{PageDescription}} * {{Parameter|integerVariableOrLiteral%}} is converted to two ASCII characters. * INTEGER values can range from -32768 to 32767. * MKI$ string values can be converted back to numerical INTEGER values using CVI. * The function takes up less byte spac...") |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 16: | Line 16: | ||
{{PageExamples}} | {{PageExamples}} | ||
''Example:'' How MKI$ creates a two byte string integer value to save file space. | ''Example:'' How MKI$ creates a two byte string integer value to save file space. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl | {{Cl|SCREEN}} 12 '_PRINTSTRING requires a graphic screen mode | ||
DO | DO | ||
{{Cl|COLOR}} 14: {{Cl|LOCATE}} 13, 20: {{Cl|INPUT}} "Enter an Integer from 1 to 32767(0 quits): ", number% | {{Cl|COLOR}} 14: {{Cl|LOCATE}} 13, 20: {{Cl|INPUT}} "Enter an Integer from 1 to 32767(0 quits): ", number% | ||
Line 32: | Line 32: | ||
{{Cl|_PRINTSTRING}} (252, 300), "{{Cl|MKI$}} value = " + Q$ + MKIvalue$ + Q$ 'print ASCII characters | {{Cl|_PRINTSTRING}} (252, 300), "{{Cl|MKI$}} value = " + Q$ + MKIvalue$ + Q$ 'print ASCII characters | ||
{{Cl|LOOP}} | {{Cl|LOOP}} | ||
{{Cl|END}} | {{Cl|END}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{ | {{Small|Code by Ted Weissgerber}} | ||
:''Explanation:'' INPUT in QB64 limits integer entries to 32767 maximum. MOD 256 finds the part of a value from 0 to 255 while the second value is the number of times that 256 can go into the value. [[_PRINTSTRING]] can print all of the [[ASCII]] characters. | :''Explanation:'' INPUT in QB64 limits integer entries to 32767 maximum. MOD 256 finds the part of a value from 0 to 255 while the second value is the number of times that 256 can go into the value. [[_PRINTSTRING]] can print all of the [[ASCII]] characters. | ||
{{PageSeeAlso}} | {{PageSeeAlso}} |
Latest revision as of 22:37, 11 February 2023
The MKI$ function encodes an INTEGER numerical value into a 2-byte ASCII STRING value.
Syntax
- result$ = MKI$(integerVariableOrLiteral%)
Description
- integerVariableOrLiteral% is converted to two ASCII characters.
- INTEGER values can range from -32768 to 32767.
- MKI$ string values can be converted back to numerical INTEGER values using CVI.
- The function takes up less byte space in a file than using the text numerical value when the value is over 2 digits.
- When a variable value is used with PUT a numerical value is converted automatically in RANDOM and BINARY files.
Examples
Example: How MKI$ creates a two byte string integer value to save file space.
SCREEN 12 '_PRINTSTRING requires a graphic screen mode DO COLOR 14: LOCATE 13, 20: INPUT "Enter an Integer from 1 to 32767(0 quits): ", number% IF number% < 1 THEN EXIT DO CLS A$ = CHR$(number% MOD 256) 'first digit(0 to 255) B$ = CHR$(number% \ 256) 'second digit(0 to 127) MKIvalue$ = A$ + B$ Q$ = CHR$(34) strng$ = "CHR$(" + LTRIM$(STR$(number% MOD 256)) + ") + CHR$(" + LTRIM$(STR$(number% \ 256)) + ")" COLOR 11 _PRINTSTRING (222, 252), STR$(number%) + " = " + strng$ _PRINTSTRING (252, 300), "MKI$ value = " + Q$ + MKIvalue$ + Q$ 'print ASCII characters LOOP END |
- Explanation: INPUT in QB64 limits integer entries to 32767 maximum. MOD 256 finds the part of a value from 0 to 255 while the second value is the number of times that 256 can go into the value. _PRINTSTRING can print all of the ASCII characters.
See also