Jose's Read Only Forum 2023

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Chris Chancellor on October 10, 2018, 04:18:28 AM

Title: Byte pointer issue
Post by: Chris Chancellor on October 10, 2018, 04:18:28 AM
Hello Charles

i have modified your program in the O2 forum
https://www.oxygenbasic.org/forum/index.php?topic=1781.msg19343;topicseen#msg19343 (https://www.oxygenbasic.org/forum/index.php?topic=1781.msg19343;topicseen#msg19343)

but did not get correct results.


' program to print a byte character of a string
' it prints out the Ascii code of that character
' Prin_OneChar.o2bas

$ filename "Prin_OneChar.exe"
uses rtl64

wchar w[11] = "1234567890"
byte b at strptr w


print    " 1st  position  byte  Ascii  : "    b[1]   "      Actual character : "   chr(b[1])            '  display 1
print    " 5th position   byte  Ascii  : "    b[5]   "      Actual character : "   chr(b[5])           '  display 3  ??  should be 5

print    " 9th position   byte  Ascii  : "    b[9]   "      Actual character : "   chr(b[9])        '  display  5 ??  should be  9
print    " 11th position   byte  Ascii  : "    b[11]   "      Actual character : "   chr(b[11])     ' display  6  ??  should be 0



for example,  b[5]  would display 3  instead of 5

while  b[9]  would display 5 instead of 9

maybe i'm wrong in the code,  what would be better code to resolve this?

Thanxx

Title: Re: Byte pointer issue
Post by: José Roca on October 10, 2018, 06:30:26 AM
Change

byte b at strptr w

to

word b at strptr w

Unicode uses 2 bytes (a word), not single bytes.
Title: Re: Byte pointer issue
Post by: Chris Chancellor on October 10, 2018, 07:28:13 AM
Thanxx a lot Jose

You are very sharp !