Integers Integers KenshinHimura (Programmer) (OP) 12 Jan 04 15:40 Is there any possible way to get unsigned integer in qbasic. Or basically any other data type that is exactly 16-bits without negative numbers? RE: Integers qbasicking (Programmer) 12 Jan 04 16:13 You could do this using regular integers. The first bit tells the computer if the number is positive or negative. So you could use that as a 16th place. Take the number, if its negative add 32768 to it. Do you understand me? This is hard to explain.1001001000101010 = -4650 in qbasicthe first 1 means that it is negative, you could use it to make a larger number 37418. RE: Integers KenshinHimura (Programmer) (OP) 12 Jan 04 16:17 Yeah thats what i wanted to do (get rid of the first bits function in qbasic), but I want to be able to get up too 65535 with an actual 16-bit integer. I heard that it can be done in asm as integers in asm are 16-bit unsigned so they can go 0 to 65535. Is this true? RE: Integers tsh73 (Programmer) 13 Jan 04 03:53 Integers in asm is anything you want them to be. Basically, it's for programmer to choose - signed or not.Anyway.Suggestion to your problem:you want to store things 16 bit but work 0..65535?Then you can store them Integer or String *2 and wrote a pair of functions the would convert them to (and from) 0..65535 LONG.Of cource it would made your program slower (not sure qbasic have enough power to write NES emulator in it, anyway) RE: Integers CodePost (Programmer) 13 Jan 04 09:34 Hello. I happened to just now be reading a document from the QuickBasic Knowledge Base that covers this stuff and have posted a small portion of it for you here since I can't dig up a url for it at the moment. You can get the entire QB KB (freeware) at my site if you'd like to have it. It's helped me find answers to many QB questions.- Davhttp://www.thecodepost.comHere is the simplest function to convert a 2 byte unsigned integer(stored in the Basic variable num%) to an unsigned number stored in aBasic LONG integer: num% = -1 PRINT unsignedlong&(num%) ' Prints 65535 FUNCTION unsignedlong& (num%) IF num% < 0 THEN unsignedlong& = num% + 65536 ELSE unsignedlong& = num% END IF END FUNCTIONYou can also convert an unsigned integer to a positive Basic LONGinteger using bit manipulation as follows:1. Check if the integer is positive or zero. If Basic already recognizes the number as positive or zero, then either use it as is, or assign it directly to a long integer and skip the next three steps.2. Otherwise, if the number (x%) is negative, then set the high bit to zero, as follows: x% = x% AND &H7FFF&3. Assign the number to a long integer, as follows: y& = x%4. Set the 15th bit (counting from bit zero) back to a one, as follows: y& = (y& OR &H8000&) The long integer (y&) now contains the correct positive integer that the other-language routine meant to pass back to Basic.Here is the simplest bit manipulation function to convert an unsignedinteger to a positive Basic LONG integer: num% = -1 PRINT Unsigned&(num%) ' Prints 65535 FUNCTION Unsigned&(param%) Unsigned& = &HFFFF& AND param% END FUNCTIONThe following program converts the unsigned integer stored in x% to apositive LONG integer stored in y&:x% = -1 ' -1 in two's complement is 65535 as unsigned integerIF x% < 0 THEN ' Set the 15th bit to zero (counting from bit 0): x% = (x% AND &H7FFF&) ' Assign it to a LONG integer: y& = x% ' Set the 15th bit back to a one: y& = (y& OR &H8000&)ELSE y& = x%END IFPRINT y& ' Prints 65535 RE: Integers KenshinHimura (Programmer) (OP) 13 Jan 04 17:16 Yeah I wanted to get an unsigned integer (so 0 to 65535) in qbasic without it being long, but it was just a curosity question neway so i could just use LONG. The only way i found is that for some reason HEX CONSTants were 16-bit unsigned so i figured maybe there was another way for non constants, but oh well since asm is the only way neway (BTW does ne1 know any good begginners ASM tutorials?). I'm not trying to make an NES emulator, but an NES rom maker (with NESASM) library (dubbed NES QUIK.....get it Nintendo Entertainment System Quick Library...hahahahahahaha) so that I didn't have to remeber all the "special" memory addresses, but then i decided i would try to get a simulation in qbasic so that I could choose to either compile it into an NES ASM file or try to simulate what it would do once compiled and run on an emulator. The only problem is that I can't DIM past 32676 and the memory addresses are 16-bit so I need to DIM to 65535. There was a NES emulator made in qbasic (even though it wasn't that good) that worked.