Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Forcing unsigned calculations
#43
It does, trust me Big Grin

Some bit theory:

Signed integers are stores using two's complement for negative numbers. That means that not only the bit sign is 1, but the rest of the bits are complemented using that technique. That's why everything gets screwed when trying to shift, rotate, or do bitwise stuff to signed numbers.

INTEGERs are 16 bits, that means that in memory they are comprised of two bytes. The i86 family of computers use big endian, that is, if a number has two bytes it stores first the less significant and then the most significant. "&H0077" in integer, for example, has two bytes: &H00 and &H77, but in memory they are stored "77, 00".

QB's MKI$ creates a string that represents a integer number, that is, it reads the memory address where the number is and it creates a two characters string with a exact copy of the memory there. That means that for number "&H0077" it returns a string CHR$(77) + CHR$(0). My small routine just takes the first byte, assuming that you are always using 8 bits values. The sign is contained in the second byte, 7th bit.

This by itself doesn't look very convincing, but you have to use it combined with my other routine which makes an integer out of two chars (CVI): CVI (CHR$(77) + CHR$(0)) = &H0077.

The pseudocode is the following:

Code:
DO WHILE NOT EOF
   Char = GET CHARACTER FROM FILE
  
   ' Now we make an always positive number using the char readed,
   ' No matter if it is positive or negative:
   IntegerValue = CVI (Char + CHR$(0))

   ' Now we do the encription
   NewIntegerValue = Do Nasty Things to IntegerValue

   ' Now we have to convert to a char again:
   EncryptedChar = LEFT$( MKI$( IntegerValue ), 1)

   ' Write to file
   PUT CHARACTER TO FILE EncryptedChar
LOOP

This way we get a "unsigned char pseudo-type". IntegerValue is always gonna be in the range 0 - 255. You only have to be careful and not to go out of bounds with calculations in the encryption part.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Messages In This Thread
Forcing unsigned calculations - by Zack - 02-16-2004, 08:18 AM
Forcing unsigned calculations - by Zack - 02-16-2004, 08:33 AM
Forcing unsigned calculations - by Zack - 02-16-2004, 08:38 AM
Forcing unsigned calculations - by Zack - 02-16-2004, 08:46 AM
Forcing unsigned calculations - by adosorken - 02-16-2004, 10:05 AM
Forcing unsigned calculations - by Antoni Gual - 02-16-2004, 05:24 PM
Forcing unsigned calculations - by Zack - 02-16-2004, 08:05 PM
Forcing unsigned calculations - by Agamemnus - 02-16-2004, 08:06 PM
Forcing unsigned calculations - by Zack - 02-16-2004, 08:08 PM
Forcing unsigned calculations - by TheBigBasicQ - 02-16-2004, 08:37 PM
Forcing unsigned calculations - by Agamemnus - 02-16-2004, 08:38 PM
Forcing unsigned calculations - by TheBigBasicQ - 02-16-2004, 08:47 PM
Forcing unsigned calculations - by adosorken - 02-16-2004, 09:20 PM
Forcing unsigned calculations - by Zack - 02-16-2004, 09:44 PM
Forcing unsigned calculations - by na_th_an - 02-16-2004, 10:05 PM
Forcing unsigned calculations - by Zack - 02-16-2004, 10:22 PM
Forcing unsigned calculations - by na_th_an - 02-16-2004, 10:41 PM
Forcing unsigned calculations - by Zack - 02-16-2004, 11:06 PM
Forcing unsigned calculations - by Mango - 02-17-2004, 05:55 AM
Forcing unsigned calculations - by Zack - 02-17-2004, 08:14 AM
Forcing unsigned calculations - by Agamemnus - 02-17-2004, 08:45 AM
Forcing unsigned calculations - by Zack - 02-17-2004, 08:50 AM
Forcing unsigned calculations - by Mango - 02-17-2004, 10:42 AM
Forcing unsigned calculations - by Zack - 02-17-2004, 07:33 PM
Forcing unsigned calculations - by TheBigBasicQ - 02-18-2004, 01:17 AM
Forcing unsigned calculations - by Zack - 02-18-2004, 01:57 AM
Forcing unsigned calculations - by TheBigBasicQ - 02-18-2004, 01:58 AM
Forcing unsigned calculations - by Zack - 02-18-2004, 02:02 AM
Forcing unsigned calculations - by TheBigBasicQ - 02-18-2004, 02:14 AM
Forcing unsigned calculations - by na_th_an - 02-18-2004, 04:07 AM
Forcing unsigned calculations - by Zack - 02-18-2004, 04:37 AM
Forcing unsigned calculations - by Mango - 02-18-2004, 06:31 AM
Forcing unsigned calculations - by Hard Rock - 02-18-2004, 06:38 AM
Forcing unsigned calculations - by na_th_an - 02-18-2004, 06:40 AM
Forcing unsigned calculations - by Hard Rock - 02-18-2004, 06:43 AM
Forcing unsigned calculations - by Zack - 02-18-2004, 07:43 AM
Forcing unsigned calculations - by na_th_an - 02-18-2004, 09:08 AM
Forcing unsigned calculations - by Zack - 02-18-2004, 06:55 PM
Forcing unsigned calculations - by na_th_an - 02-18-2004, 07:54 PM
Forcing unsigned calculations - by TheBigBasicQ - 02-18-2004, 09:28 PM
Forcing unsigned calculations - by Zack - 02-18-2004, 11:53 PM
Forcing unsigned calculations - by Mango - 02-19-2004, 04:53 AM
Forcing unsigned calculations - by Zack - 02-19-2004, 07:28 AM
Forcing unsigned calculations - by Agamemnus - 02-19-2004, 08:11 AM
Forcing unsigned calculations - by Zack - 02-19-2004, 08:40 AM
Forcing unsigned calculations - by relsoft - 02-19-2004, 11:11 AM
Forcing unsigned calculations - by TheBigBasicQ - 02-19-2004, 02:19 PM
Forcing unsigned calculations - by Zack - 02-19-2004, 07:21 PM
Forcing unsigned calculations - by TheBigBasicQ - 02-19-2004, 07:24 PM
Forcing unsigned calculations - by Zack - 02-19-2004, 07:28 PM
Forcing unsigned calculations - by TheBigBasicQ - 02-19-2004, 07:30 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)