|
Post by DJLinux on Dec 11, 2008 20:03:35 GMT -5
for i=1 to 5 c$=ReadChar(f) print asc(c$) +"," next  if ReadChar() reads a single byte betweeen 0-255 ASC(c$) should never return "-161" ?!?  You can see the sign bit is set 0x8C but i would accept from ReadByte() function a number between -128 and +127 not from ASC(c$) function or i'm wrong ? as a workaround i use c$=chr$(Readbyte(f) and 127) Joshy
|
|
|
Post by Nicky Peter Hollyoake on Dec 12, 2008 7:01:47 GMT -5
I'm not to sure the problem because I get no negative numbers, but you could always use ... "ABS ( ASC ( Char ))"?
- Nicky
|
|
|
Post by DJLinux on Dec 12, 2008 8:33:08 GMT -5
no ABS() is wrong abs(-161) = 161 c$ = 0x8C = 140 decimal proof it self 8*16+12=140
a char is between 0 and 255 a byte is between -128 and +127 a unsigned byte 0 and 255
now if you have in a file a letter with code 140 c$=ReadChar(hFile) ASC(c$) returns -161 not 140 and an ABS(-161) isn't 140
Joshy
|
|
|
Post by dw817 on Apr 17, 2009 19:02:02 GMT -5
Nope, Nicky. It's a real error, and it's not just file related. Can repeat error here a different way:
dim c$=chr$(-116) print asc(c$)
Should return positive # in all cases or cry an error of boo hoo for no negative # for chr$() Does neither. I see ASCII does return a negative #. I'm - not sure who this would affect if changed, however, I would prefer it 0-255 instead of -128 to 127 as it is now.
Hope This Helps !
|
|
|
Post by dw817 on Feb 22, 2013 19:38:06 GMT -5
Bump. Did anyone ever fix this error ? Tried it again on B4GL v2.5.8. cls dim a$ a$=chr$(-1) printr a$ printr asc(a$) drawtext() end results: Y -1 I think we're gonna have to be very careful and not accidentally feed a negative number into ASC function or get really fouled up answers. 
|
|