Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Chopping a Number 1

Status
Not open for further replies.

pya

Technical User
Dec 18, 2020
40
AU
Folks,

How do I chop and print a 6 digit number?

If my number is 123456, I want to out put 12 or 34 or 56.

Your help appreciated.

Thanx

pya
 
Hi mikrom,

I December 2020 I asked about how to handle large numbers in QB64 as I was stuck at 16 digits.
You advised that I use strings.

But today I used

DIM As _Unsigned _Integer64, P

and correctly tested a 20-digit Prime!!

Made my day.

THANX

pya


 
Hi pya,

Oh yeah, back then in 2020 I wasn't very interested in Basic and back then I didn't find and read this important article about QB64 data types either
I just thought that Basic is an old programming language and that the QB64 compiler certainly doesn't have the ability to work with large numbers.
I only found this article yesterday and it completely changed my mind. But something like that also happens :)
So I'm already smarter today and I know that QB64 has various built-in data types, including those that allow you to work with large numbers.

By the way, Basic was my first programming language that I learned at college in the 1980s.

I was happy to help you with your research.
 
I finally installed QB64 on my Linux PC and was able to compare it with the BASIC256 that I had previously installed.

In terms of speed when processing numbers - for example when searching for prime numbers - the QB64 is far superior to the BASIC256.

But both are really good, and what's great is that they are both cross-platform for Linux and Windows.

For someone who is just starting out programming, BASIC256 is definitely easier to use - very nice and easy to use.

Those who, on the other hand, have a little more programming experience, are not afraid of the very classic retro look of the IDE and want to develop astonishingly powerful multi-platform applications in Basic, will appreciate the QB64 more.
 
Thanx for the extra info mikrom.

I am quite happy with my QB64.

Although I still run into problems with large numbers when testing for primes.

Your advice regards using
DIM As _Unsigned _Integer64, P
correctly tested a 20-digit Prime BUT fails when testing 21 digit numbers.
The screen input will not allow input of the 21st digit during input.
Very strange.

If and only if, when you have time, can you help.

I do coding for fun and to keep my grey cells ticking. (along with Sudoku).
So, if you are busy and you feel I am stretching our online friendship toooo far, please forget and forgive!

I can send you my Prime Testing program if you wish.

Regards

pya
 
Any other data type available for numbers larger than 20 digits?
 
The data type _FLOAT supports larger numbers, but it is unfortunately not suitable for calculations with large integers. For example, when I tried to find all divisors of the number N = 12345678901234567890, then using UNSIGNED _INTEGER64 data type delivered me first three divisors 2, 3, 5 which is true. But when I changed the data type to _FLOAT, then the program delivered me first three divisors 2, 4, 7, which is false. It did not calculate the divisor 3, but 3 is sure the divisor of N because sum of digits of N is 90 what is divisible by 3. Similarly it did not calculate the divisor 5, which must be true because N ends with 0.
 
I learnt something new today.

Thanx

pya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top