Restored from previous forum. Originally posted by Justin.
 This may be a basic question but how do you work with unsigned integers?
i have to peek 1 byte from a memory address, the value is $80 , 128 dec, but is stored as -128 signed.
i know how to display it with stru(), but i need to work with the unsigned value. how?
			
			
									
									
						Signed to unsigned ints?
- 
				BackupUser
- PureBasic Guru 
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by ebs.
Justin,
Signed vs. unsigned values are only a matter of how the value is interpreted by PureBasic. An unsigned byte of -128 and a signed byte of 128 both hold the same value, as you said.
The easiest way to convert a signed byte to an unsigned one is to add 256 if it is less than zero:
Eric
			
			
									
									
						Justin,
Signed vs. unsigned values are only a matter of how the value is interpreted by PureBasic. An unsigned byte of -128 and a signed byte of 128 both hold the same value, as you said.
The easiest way to convert a signed byte to an unsigned one is to add 256 if it is less than zero:
Code: Select all
If Byte < 0
  Byte + 256
EndIf
Originally posted by Justin
This may be a basic question but how do you work with unsigned integers?
i have to peek 1 byte from a memory address, the value is $80 , 128 dec, but is stored as -128 signed.
i know how to display it with stru(), but i need to work with the unsigned value. how?
- 
				BackupUser
- PureBasic Guru 
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
- 
				BackupUser
- PureBasic Guru 
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
- 
				BackupUser
- PureBasic Guru 
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
- 
				BackupUser
- PureBasic Guru 
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by geoff.
Yes, Fred's method is fast, but it still slows things down.
Suppose you have a huge image array: pixel(x,y)
To increase the brightness you want to use:But you have to use:This slows things significantly for megapixel image processing. You could use word arrays, but this is unattractive because the byte arrays already require huge amounts of memory.
			
			
									
									
						Yes, Fred's method is fast, but it still slows things down.
Suppose you have a huge image array: pixel(x,y)
To increase the brightness you want to use:
Code: Select all
for x=1 to wd  for y=1 to ht
    pixel(x,y)=n * pixel(x,y)
  next y
next xCode: Select all
for x=1 to wd
  for y=1 to ht
    longpix.l=pixel(x,y) & $FF
    pixel(x,y)=n * longpix
  next y
next x- 
				BackupUser
- PureBasic Guru 
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by tinman.
 
That code won't work (well). Floats have less accuracy than longs, so by doing this large values may lose some of the lower value digits. Whether this matters to your application is another story.
--
I used to be a nihilist but I don't believe in that any more.
(Win98first ed. + all updates, PB3.62, external editor)
			
			
									
									
						A fairly old topic, but Geoff's post brought it to my pedantic eye. Andre already knows my answer to thisOriginally posted by Justin
a.f= long.l + 4294967296

That code won't work (well). Floats have less accuracy than longs, so by doing this large values may lose some of the lower value digits. Whether this matters to your application is another story.
--
I used to be a nihilist but I don't believe in that any more.
(Win98first ed. + all updates, PB3.62, external editor)
- 
				BackupUser
- PureBasic Guru 
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm