Bug with >> and highest bit set

Found an issue in the documentation ? Please report it here !

Moderator: Documentation Editors

infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Bug with >> and highest bit set

Post by infratec »

Code: Select all

Test.l = $80000000
Debug Hex(Test >> 24, #PB_Long)
It should return 80,
but it returns FFFFFF80

If the highest bit is set, it fills with 1 and not with 0 like it is written in the help.

Code: Select all

Test.l = $7F000000
Debug Hex(Test >> 24, #PB_Long)
Shows 7F, which is correct.

The shift operator should not respect a sign bit.

PB 5.73 x86 on Win10 x64
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Bug with >> and highest bit set

Post by mk-soft »

Purebasic bit-shift ">>" is always signed!

Link: Bitshift and Rotation

Code: Select all

; Bitshift right shift
Procedure SHR32(value.l, count.l = 1)

  !mov eax, dword [p.v_value]  
  !mov ecx, dword [p.v_count]
  !shr eax, cl
  ProcedureReturn
  
EndProcedure

lVal.l = $80000000

r1.l = SHR32(lVal, 24)
Debug RSet(Hex(r1), 8, "0")
Exception ASCII and Unicode types (a1.a, u1.u)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Bug with >> and highest bit set

Post by infratec »

Hm ... PB is not assembler

And in the german help is written:
Weggefallene Bits auf der linken Seite der Variablen werden mit 0 aufgefüllt.
No more no less.

You can choose where the bug is, but there is a bug.
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Bug with >> and highest bit set

Post by User_Russian »

This error is because PB does not support unsigned variables 4 and 8 bytes.
viewtopic.php?f=3&t=52929
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Bug with >> and highest bit set

Post by mk-soft »

Description not complete ...
f.b=-128 >> 1 ; Der Wert von f ergibt -64. -128=%10000000, -64=%11000000. Beim Verschieben nach Rechts bleibt das Vorzeichen ("most significant bit") gleich.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Bug with >> and highest bit set

Post by infratec »

Ok, so the functionality is correct, but the german documentation is wrong.

Sorry, I don't read the examples if the description is clear.

An admin should move this report into the documentation bug section.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Bug with >> and highest bit set

Post by Andre »

Sorry, I don't see, what should be changed in the (german) docs. Any concrete suggestions?
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Bug with >> and highest bit set

Post by Demivec »

Andre wrote: Sat Mar 11, 2023 9:26 pm Sorry, I don't see, what should be changed in the (german) docs. Any concrete suggestions?
German is not my native language but I would suggest for the description of the '>>' operator in the German text :
Bitweise Verschiebung nach rechts. Durch die Verwendung dieses Operators verschieben Sie jedes Bit der Variablen auf der linken Seite des Operators um die Anzahl der auf der rechten Seite des Operators angegebenen Bits nach rechts. Das Bit ganz links wird repliziert, um alle freien Bitpositionen aufzufüllen, die auf der linken Seite der Variablen weggelassen werden. Wenn das Ergebnis dieses Ausdrucks nicht verwendet wird und sich links vom Operator eine Variable befindet, wird der Wert dieser Variablen verschoben. Es hilft auf jeden Fall, wenn Sie Binärzahlen verstehen, bevor Sie diesen Operator verwenden. Obwohl Sie es auch so verwenden können, als ob Sie jede Position, die Sie verschieben, durch einen Faktor von 2 teilen würden. Hinweis: Die Durchführung dieser Schichtoperation ist in der Regel kostengünstiger als die vergleichbare Teilung.
Likewise, for the English text:
Bitwise right shift. By using this operator, you shift each bit of the variable on the left side of the operator to the right by the number of bits specified on the right side of the operator. The leftmost bit is replicated to fill in any vacant bit positions that are omitted on the left side of the variable. If the result of this expression is not used and there is a variable to the left of the operator, the value of that variable is shifted. It definitely helps if you understand binary numbers before using this operator. Although you can also use it like dividing each position you move by a factor of 2. Note: Performing this layering operation is usually cheaper than the comparable division.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Bug with >> and highest bit set

Post by Andre »

Thanks demivec! Anyway @Fred should take a look, what he exactly wants to be written in the docs 8)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Post Reply