## Chopping a Number

## Chopping a Number

(OP)

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

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

## RE: Chopping a Number

Use the MID$() function

## CODE

Skip,

_{ Just traded in my OLD subtlety... for a NUance!}"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

You Matter...

unless you multiply yourself by the speed of light squared, then...

You Energy!

## RE: Chopping a Number

## CODE

Skip,

_{ Just traded in my OLD subtlety... for a NUance!}"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

You Matter...

unless you multiply yourself by the speed of light squared, then...

You Energy!

## RE: Chopping a Number

Thanx, mate.

Much appreciated.

pya

## RE: Chopping a Number

I got an Error when I ran your code.

Error File attached.

Regards

pya

## RE: Chopping a Number

MID$ works with strings, not numbers, therefore the error

With numbers use operators:

Example - tested with BASIC256:\: result of integer divisionmod: modulo or remainder of division## CODE

Output:

## CODE

## RE: Chopping a Number

## CODE

## RE: Chopping a Number

## CODE

## RE: Chopping a Number

Thanx for your help.

I used your previous post and wrote a simple number guessing program for my grandkids.

I also picked up info from Google but I do not understand Lines 80, 100 and 110. (see attached File).

If you can clarify I would be grateful.

Also, see if you can 'break' the program.

I would love to make it foolproof before I show it to my kids!

Thanx

pya

## RE: Chopping a Number

this reads one character from keyboard, i.e. it waits until you press a key on keyboard:

## CODE

this is integer division, that mean division without rest:

## CODE

this is modulo operation, that means the rest after the integer division:

## CODE

In your case you don't need 2 lines

## CODE

## CODE

## CODE

## RE: Chopping a Number

Thanx for your quick response.

Your explanations are very clear.

And, thanx to you I am increasing my knowledge.

I did Fortran 4 programming in college but that was in the 70s.

Once again, thanx for all your help.

I have 1 more question if you don't mind.

I use a PRINT statement to insert a blank line.

If I want to insert multiple blank lines, say 3, how do I do that?

Regards & Thanx

pya

## RE: Chopping a Number

## CODE

then you can do following

## CODE

## RE: Chopping a Number

## RE: Chopping a Number

Once again thanx for your help.

No, I have not worked out why it is outputting a 0 when the Input is 99.

In fact, I am trying to increase the range of the input from 1 to 999 (or 998).

Any help you can provide will be appreciated.

Regards

pya

## RE: Chopping a Number

You are using magic number 13837 * 73 = 1010101, but when you multiply it with 99 then the result is too big for QB64 and this causes inaccuracy in further calculations.

For example, when you try this

## CODE

## CODE

Btw, it is problem in QB64 only, in Basic256 your program works.

To work around this problem in QB64, you have to take smaller magic number.

So if you take instead of

1010101 = 13837 * 73

smaller number

10101 = 3 * 7 * 13 * 37

than it will work in QB64

Now, when you try this

## CODE

## CODE

So your corrected program which works in QB64 for input number 99 could be:

## CODE

## RE: Chopping a Number

## RE: Chopping a Number

Is BASIC256 more advanced than QB64?

Is it possible to get and install Basic256?

Will Basic256 handle large numbers? Numbers greater than 16 digits?

and, if yes, will my QB64 programs work in Basic256?

Regards

pya

## RE: Chopping a Number

Regarding what you are programming, I don't know if Basic256 is more advanced than QB64 - in my opinion, not too much. For example your example works in Basic256 with

## CODE

## CODE

Your QB64 programs will probably not work in Basic256, because for example as I mentioned above Basic256 only support one type of while loop and QB64 supports many types.

Basic256 seems to be a new language dialect, while QB64 is compatible with several classic Basic dialects such as QBasic and others.

But you can install it alongside QB64, compare both and if you don't like it, then you can uninstall it.

## RE: Chopping a Number

You asked for numbers greater than 16 digits.

I found this description of QB64 datatypes:

https://www.qb64.org/wiki/Data_types#Unsigned_Inte...

By default when data type is not declared the variables are handled as SINGLE datatype, so if we want to work with bigger numbers we can declare them as DOUBLE.

When we only need very big positive integers, we can use _UNSIGNED _INTEGER64 datatype.

This datatype is 8 bytes = 64 bits long, so we can work with numbers from 0 to 2^64 - 1 = 18 446 744 073 709 551 615, which is more than 16 digits.

I tried in QB64 this example and it looks good:

## CODE

## RE: Chopping a Number

I will now spend a fair amount of time trying to understand and run your code.

Thanx for all your help.

I will now try and leave you alone - till next time!

Regards

pya

## RE: Chopping a Number

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

## RE: Chopping a Number

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

https://www.qb64.org/wiki/Data_types.

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.

## RE: Chopping a Number

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.

## RE: Chopping a Number

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

## RE: Chopping a Number

In the table named

Data type limitshere https://www.qb64.org/wiki/Data_types#Unsigned_Inte...you can see that the

Maximum valueofUNSIGNED _INTEGER64is18,446,744,073,709,551,615That's the 20 digit limit. It seems, that you reached the limit, 21 digit integers are not possible with this data type.

## RE: Chopping a Number

## RE: Chopping a Number

## RE: Chopping a Number

Thanx

pya