Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here




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

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 qbasic
the first 1 means that it is negative, you could use it to make a larger number 37418.

RE: Integers

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

Integers in asm is anything you want them to be. Basically, it's for programmer to choose - signed or not.
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


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.

- Dav


Here is the simplest function to convert a 2 byte unsigned integer
(stored in the Basic variable num%) to an unsigned number stored in a
Basic LONG integer:

   num% = -1
   PRINT unsignedlong&(num%)   ' Prints 65535
   FUNCTION unsignedlong& (num%)
       IF num% < 0 THEN
               unsignedlong& = num% + 65536
               unsignedlong& = num%
       END IF

You can also convert an unsigned integer to a positive Basic LONG
integer 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

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

      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 unsigned
integer to a positive Basic LONG integer:

   num% = -1
   PRINT Unsigned&(num%)   ' Prints 65535
   FUNCTION Unsigned&(param%)
      Unsigned& = &HFFFF& AND param%

The following program converts the unsigned integer stored in x% to a
positive LONG integer stored in y&:

x% = -1     ' -1 in two's complement is 65535 as unsigned integer
IF 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&)
   y& = x%
PRINT y&   ' Prints 65535


RE: Integers

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close