Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Forcing unsigned calculations
#41
Sincerely, I don't know. What I know is that you better don't mess with signed stuff. For what you want to do you can use my second "routine":

Code:
myString = LEFT$( MKI$( (---here we do our encryption---) ), 1)
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#42
But I still don't see how that would eliminate the sign. Sad
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#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
#44
zack, would you stop fretting and write some code and experiment?
Reply
#45
That's not my attitude, TBBQ - just like when doing chemistry, you don't throw in hydrochloric acid and ammonium sulfate with zinc and see what happens. You study the theory. Then you try.
Nath: I think I'm seeing it now...I've gotta learn more about bit theory. Hm. I've implemented it fine in C...now I'll work with your method and see what I get in QB. Thanks, mate. Smile
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#46
Quote:That's not my attitude, TBBQ - just like when doing chemistry, you don't throw in hydrochloric acid and ammonium sulfate with zinc and see what happens. You study the theory. Then you try.
Nath: I think I'm seeing it now...I've gotta learn more about bit theory. Hm. I've implemented it fine in C...now I'll work with your method and see what I get in QB. Thanks, mate. Smile

Well...what you suggest is the equivalent to:

z=0
do
poke z, rnd*1000
z=z+1
loop

such reckless behavior is not at all similar to something more controlled like:

a% = 123
b% = 456
c% = a% xor b%

print c%

This is the kind of testing that was being refered to...you can learn loads by experimenting...both in chemistry and with computers...as long as you know *enough* not to be totally reckless.

Cheers
Reply
#47
It was a general analogy, I agree - but still, I would much prefer to study three chapters on inheritence, then dive into code, and build a class, rather than reading the first paragraph in one chapter, and trying to get it.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#48
Reckless endangerment of computers.

Where's that shifty face when you need it?
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#49
You mean this one: Confusedhifty:
Although generally I love reckless endangerement of computers. Nothing gives me more satisfaction than fooling around with DOS 6 on a 386, in the process completely destroying it.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#50
Quote:It was a general analogy, I agree - but still, I would much prefer to study three chapters on inheritence, then dive into code, and build a class, rather than reading the first paragraph in one chapter, and trying to get it.

If you do that, You'll be left behind. Experience is the best teacher. :*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)