PeekW(@Var) could be > than 32767??

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Im getting some strange behavior in one of my functions reading and writing mp3s and when i debug it i get than reading a buffer with PeekW gives me more than 32767, im i missing something?

See this example:

value.l = 56741
valor.w = PeekW(@value)

Debug valor
Debug StrU(valor,#Word)
Debug Str(valor)

Need help here please !!

Best Regards

Ricardo

Dont cry anymore...:)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

I will try to be more clear about my problem.

Im doing this:

Code: Select all

For i = buffer To (buffer + (length/2)) - 1 Step 4
  ChD.w = PeekW(i)
  ChI.w = PeekW(i + 2)
If ChD > 32767 Or ChI > 32767
  MessageRequester("Oops",Str(Chd),0)
  End
EndIf
WriteStringN(Str(ChD))
WriteStringN(Str(ChI))
NewD.w = ChD * (-1)
NewI.w = ChI * (-1)
ChD = NewD
ChI = NewI
PokeW(i,ChD)
PokeW(i + 2,ChI)
Next i
Thats, im trying to change the sign on every word.
If you see, if a word value was > 32767 i get a prompt and the program ends, thats never happens.
But if i read the file with the values readed i get somethig like:

62521
63849
3015<< was * -1 result
1687<< was * -1 result

Those two values are greater than 32767!! But the IF dosent detects it?

I tried to change the .w for .f in the variables that receive the *-1 result and dosent works too.
I have done this same thing in the past (reading from a file) with success, receiving the expected results, thats why i dont get where is the problem.

In my old code (reading from a file) i get values from -32768 to 32767 and its easy to change the sign, try this:

valor.w = -32767
valor = valor * -1
Debug valor

Best Regards

Ricardo

Dont cry anymore...:)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

Yes, the range is only up to 32767 for SIGNED Words.
Unsigned, it can be 2^16 - 1 which is 65535.

And as in memory, both are the same, only the interpretation is different, Word caan hold bigger numbers.

As you see, Str() interpret's it as -8795 because it assumes it is signed.
StrU() however interprets it as 56741, as it interprets stuff as unsigned.

Hope this cleared things up a bit...

Timo

http://freak.coolfreepages.com/
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

If a value is greater that 32767 and interpreted as signed, it is http://freak.coolfreepages.com/
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Its working now!!!

Thanks Freak :)

Code: Select all

For i = buffer To (buffer + (length)) - 1 Step 4
  ChD.w = PeekW(i) -  65536
  ChI.w = PeekW(i + 2) -  65536
  ...
Post Reply