Page 1 of 1
					
				problem with negative long numbers
				Posted: Tue Dec 23, 2008 11:07 pm
				by harkon
				looking at the following;
Code: Select all
;Why does a negative number return 8 bytes
LongValue.l=2147483647
Debug "As a long " + Str(LongValue) + " .. as hex " + Hex(LongValue)
Debug ""
LongValue=-2147483647
Debug "As a long " + Str(LongValue) + " .. as hex " + Hex(LongValue)
Debug "Shoud return FFFFFFFF .. right?"
Why does this now return a different Hex() string than it did in PB Version 4.2? I can allow for this in that if the number is negative I can just discard the first 4 bytes, but will this behavior remain, or is it something that needs fixing?
TIA, and thanks to the team for all of their efforts on 4.3.
 
			 
			
					
				
				Posted: Tue Dec 23, 2008 11:13 pm
				by Kaeru Gaman
				I think maybe because Debug casts a Quad on it?
the first Value is also Quad, but leading Zeros are not printed?
> "Shoud return FFFFFFFF .. right?"
nope. $FFFFFFFF is -1
			 
			
					
				
				Posted: Tue Dec 23, 2008 11:28 pm
				by freak
				Use #PB_Long as the second parameter to Hex() to treat it as a long value (returning FFFFFFFF in this case)
			 
			
					
				
				Posted: Tue Dec 23, 2008 11:31 pm
				by Kaeru Gaman
				Code: Select all
LongValue = -2147483648
Debug "As a long " + Str(LongValue) + " .. as hex " + Hex(LongValue, #PB_Long)
LongValue = -1
Debug "As a long " + Str(LongValue) + " .. as hex " + Hex(LongValue, #PB_Long)
a.l = $FFFFFFFF
Debug Str(a)
 
			 
			
					
				
				Posted: Wed Dec 24, 2008 4:53 am
				by Little John
				freak wrote:Use #PB_Long as the second parameter to Hex() to treat it as a long value (returning FFFFFFFF in this case)
Oh, this information is another Christmas present. 

In the (English and German) help for PB 4.30, it's not mentioned that 
Hex() can take a second parameter.
Code: Select all
Debug Hex(-1)
Debug Hex(-1, #PB_Quad)
Debug Hex(-1, #PB_Long)
Debug Hex(-1, #PB_Word)
Debug Hex(-1, #PB_Byte)
Regards, Little John
 
			 
			
					
				
				Posted: Wed Dec 24, 2008 3:47 pm
				by harkon
				Thanks everyone. As mentioned the help didn't say anything about this so I was clueless. #PB_Long does the trick. And, you're right it should have returned 8000001, had a brain fart there. Never was too great at base conversion 
 
BTW I've found a few oversights in the help, like a some of the new libraries help points to an example but there doesn't seem to be an example available. I know that help authoring is a huge undertaking, so I'm very grateful for the help given. 
Thanks to all for your help, got this one ported to PB 4.3 and works great. On to the next 

 
			 
			
					
				
				Posted: Wed Dec 24, 2008 6:55 pm
				by mk-soft
				since pb v4.3 is $FFFFFFFF not equal -1 because is casts as quad
Code: Select all
Procedure.l LONG(Value.q)
  ProcedureReturn Value
EndProcedure
Procedure.b BYTE(Value.q)
  ProcedureReturn Value
EndProcedure
#c_test1 = $FFFFFFFF ; <- casts as quad
#c_test2 = -1
If #c_test1 = #c_test2
  Debug "Equal"
Else
  Debug "Error"
EndIf
If LONG(#c_test1) = #c_test2
  Debug "Equal"
Else
  Debug "Error"
EndIf
If BYTE(#c_test1) = BYTE(#c_test2)
  Debug "Equal"
Else
  Debug "Error"
EndIf
 
			 
			
					
				
				Posted: Wed Dec 24, 2008 7:31 pm
				by Kaeru Gaman
				debug also before had casted quads...
run this is 4.2:
and also in 4.3, a long is treated as long:
so, your sentence
since pb v4.3 is $FFFFFFFF not equal -1 because is casts as quad 
is missing at least two parameters to be evaluated as True or False...