It looks like you're new here. If you want to get involved, click one of these buttons!

- 141.1K All Categories
- 104.5K Programming Languages
- 6.4K Assembler Developer
- 1.8K Basic
- 39.8K C and C++
- 4.3K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.6K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 508 Python
- 48 Ruby
- 4.3K VB.NET
- 1.6K VBA
- 20.8K Visual Basic
- 2.6K Game programming
- 311 Console programming
- 89 DirectX Game dev
- 1 Minecraft
- 110 Newbie Game Programmers
- 2 Oculus Rift
- 8.9K Applications
- 1.8K Computer Graphics
- 726 Computer Hardware
- 3.4K Database & SQL
- 522 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 256 XML Development
- 3.3K Classifieds
- 195 Co-operative Projects
- 182 For sale
- 189 FreeLance Software City
- 1.9K Jobs Available
- 600 Jobs Wanted
- 201 Wanted
- 2.9K Microsoft .NET
- 1.7K ASP.NET
- 1.1K .NET General
- 3.2K Miscellaneous
- 3 Join the Team
- 0 User Profiles
- 349 Comments on this site
- 59 Computer Emulators
- 2K General programming
- 178 New programming languages
- 609 Off topic board
- 164 Mobile & Wireless
- 38 Android
- 124 Palm Pilot
- 335 Multimedia
- 151 Demo programming
- 184 MP3 programming
- 0 Bash scripts
- 19 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 367 MS-DOS
- 0 Shell scripting
- 320 Windows CE & Pocket PC
- 4.1K Windows programming
- 885 Software Development
- 405 Algorithms
- 68 Object Orientation
- 87 Project Management
- 90 Quality & Testing
- 234 Security
- 7.5K WEB-Development
- 1.8K Active Server Pages
- 61 AJAX
- 2 Bootstrap Themes
- 55 CGI Development
- 19 ColdFusion
- 222 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 33 JQuery
- 286 WEB Servers
- 145 WEB-Services / SOAP

ranainnet
Posts: **54**Member

in Visual Basic

Hie there fellows.

Can anybody give me any idea of a new variable tyep. The question is if I need a variable that would hold more than a double tupe variable then what should I do? Is there any easy way in VB6 which will enable me to create this type of variable and do + - * / works on this type of variable?

I know double is a very very wide one which can hold more than I need, but I wonder what should I do if someone needs one that can hold more than that.

Any Ideas please.

_____________________________________________________________________________

Knowledge Is Power. Be Sure To Use This Power For Others WelFare. (;->

Can anybody give me any idea of a new variable tyep. The question is if I need a variable that would hold more than a double tupe variable then what should I do? Is there any easy way in VB6 which will enable me to create this type of variable and do + - * / works on this type of variable?

I know double is a very very wide one which can hold more than I need, but I wonder what should I do if someone needs one that can hold more than that.

Any Ideas please.

_____________________________________________________________________________

Knowledge Is Power. Be Sure To Use This Power For Others WelFare. (;->

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven LLC

© 1997-2015 Programmersheaven.com - All rights reserved.

## Comments

2,444MemberThe standard operators will not work on this type, unless you are using VB.NET (or C++, C# etc) where you can overload the * operator (and others).

In VB6 it will look like:

Class BigNumber

-Function Multiply(Takes either a numeral variable or a BigNumber class)

-... other functions like the previous

-Number property (as a string) containing the integer number contained in BigNumber)

To give you an idea of how it will look. To do this with Integer numbers is the easiest. Creating a large double will be a bit more work.

But the biggest problem is that you will have to 'reinvent' all the mathematical operators... For example: You need create an algorithm to add these 'BigNumbers' to eachother. After that, to create the multiply operator, say for the formula 25 x BigNumber1, you will need to call the Addition 25 times with BigNumber1 as parameter.

Greets...

Richard

54MemberLike should it be ok if I seperate the big number into small parts e.g.

12345679.....123456789 into

1234 5678 9... 1234 5678 9012

and put them into series of variables in my new class. And then make a function which will constract the pieces of numbers into one number.

ITS REALLY A CRITICAL WORK. Sorry for my low quality english. And thanks again.

_____________________________________________________________________________

Knowledge Is Power. Be Sure To Use This Power For Others WelFare. (;->

2,444MemberThe problem is that VB only has one unsigned type, which is the Integer. An unsigned long would be nice for this kind of work :-S

But perhaps it is easier in the first place to store your 'number' as a decimal string.

That way, you could take it character by character.

Plus would then be:

Take the first character of both strings.

Convert them to an integer and add them together (in a special function).

Then check if the number is larger than 9. If it is, remember this and substract 10 from it.

The special function should return the single decimal number that came out of the addition (with the 10 dropped from it). If the number was larger than 10, also tell this to the calling function.

Write to the new string this new answer.

Repeat this process for each character. If there was a remainder, don't forget to add this to.

Now I am sorry for my pour explanation. I don't have time right now, but I might clarify this later with an example of what I mean.

Greets...

Richard

54MemberThanks a lot for ur effort of making thinsg yasier. Don't worry, you explained well. I will let u know after completing something that might do the task of the large variable. Another thing is that,

I understand that I have to deal with the overflow to do the addition and for that I have to do recursive calling to a function. After that I can call the addition function for several times to calculate a multiplication or power.

But I don't have any idea of how to do the division task? Should I subtract(-) 155 from 23456 for several times and count a number to find out the integer portion of the result to calculate 23456/155.

Bye for now, Hope to hear form U soon.

_____________________________________________________________________________

Knowledge Is Power. Be Sure To Use This Power For Others WelFare. (;->

2,900Member:

: Can anybody give me any idea of a new variable tyep. The question is if I need a variable that would hold more than a double tupe variable then what should I do? Is there any easy way in VB6 which will enable me to create this type of variable and do + - * / works on this type of variable?

:

: I know double is a very very wide one which can hold more than I need, but I wonder what should I do if someone needs one that can hold more than that.

:

: Any Ideas please.

Use Python :-)

I think the Currency type in VB is "bigger" than the Double type.

Seriously, there are algorithms out there for performing arithmetic operations on very large numbers. I don't know how suitable VB is for implementing those algorithms. Python comes with this kind of power out-of-the-box:

[code]

>>> print 10**100

10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

[/code]

[size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

[code]

$ select * from users where clue > 0

no rows returned

[/code]

54MemberAgain I want to say that, this large number value is quite enougn to do everything I need. But what I am trying to find out is How to create a variable larger then the builtin type variables of VB6.

In short if I start with Integer variables it wont be able to hold more than about -32000 to +32000, and about 64000 if it is unsigned (although I have to check it out that whethere VB6 supports unsigned Integer variables). But if I want to make a custom LargeInteger variable that may hold upto +1234567890 to -1234567890 then what should be the most appropriate and effecient way?

Thanks for your response.

_____________________________________________________________________________

Knowledge Is Power. Be Sure To Use This Power For Others WelFare. (;->

2,444MemberFor instance: 34567/155

Substract 155 from 34567 until the remaining number is smaller than 155.

Keep a count of how many times you do this. Call this number n for now.

The remainder will be r.

You'll get an answer: n will be the integer number (dropping the remainder). If you want to round it, check if r > (155 / 2), or in words "If the remainder is larger than half the divisor".

Have fun :-)

(Note that this all is only for Integer numbers. To use decimal numbers, you'll have to think of what to do with the remainder)

Greets...

Richard

307Member: I don't know about Python, Byt VB6 also can support a very very large number. In a Double type variable VB6 can ultimately support more than 300 dizit number value.

:

: Again I want to say that, this large number value is quite enougn to do everything I need. But what I am trying to find out is How to create a variable larger then the builtin type variables of VB6.

:

: In short if I start with Integer variables it wont be able to hold more than about -32000 to +32000, and about 64000 if it is unsigned (although I have to check it out that whethere VB6 supports unsigned Integer variables). But if I want to make a custom LargeInteger variable that may hold upto +1234567890 to -1234567890 then what should be the most appropriate and effecient way?

:

: Thanks for your response.

: _____________________________________________________________________________

: Knowledge Is Power. Be Sure To Use This Power For Others WelFare. (;->

:

:

Let's see ... Long is 32-bit number (Let's talk integers for now).

Let's also suppose you need a 128-bit number, so ... you'll need four Long numbers:

[code]

FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF

[/code]

As Richard pointed out (was it Richart? I forgot ... sorry) you will need custom made functions for arithmetic operations.

I have a suggestion for division and multiplication.

You suggested that you should subtract 155 times the number 155. So you'll have something like a counter.

subtraction 154

subtraction 153

subtraction 152

... and so on...

subtraction 1

subtraction 0...

Well .. this repeats too many times. How about this:

[code]

We have X/Y. To get the result, we need Y = 1.

So ...

(X/Y) * 1 = X/Y - true

1 = (1/2) / (1/2) - true

=> (X/Y) * [(1/2)/(1/2)] = X/Y

<=> 1 X

- -

X 2 X 2 X

- * - = - OR - = -

Y 1 Y Y Y

- -

2 2

[/code]

The reason to do this is that if you look at the numbers in binary, you'll notice that multiplication and division by is done quite easy:

to multiply by 2 - simply shift the number to the left by 1 bit

to divide by 2 - shift right by 1 bit

You will have to consider carrying bits over to next part of the number.

Example (for simplicity, 16-bit number made up by two 8-bit numbers):

You have the following:

[code]

00000000 10000000

When you multiply by two, you have to shift left by 1 bit, but if you don't consider the carry-over, you will get this:

00000000 00000000

which obviously is not what you want. What you need to do is save the

first bit of the low-order byte, then do the shifting, and then add the carry-over to the high-order byte:

HI LO

initial: 00000000 10000000

save 1st bit: CARRYY_OVER = BIT1(LO) ' = LO & 10000000 (bitwise AND)

shift: 00000000 00000000

add to HI: IF CARRY_OVER <> THEN HI = HI + 1

00000001 00000000

[/code]

VB has built-in operators for shifting: SHL and SHR respectively for shifting left and right. Play around with this. Do some binary aritchemtic on paper using small numbers like two 8-bit numbers just to get a feel of how things work, and to run into some problems, which you will have to solve.

Hope I helped,

Nikolay Semov

2,444MemberI don't understand your calculation, but I do know what you are saying.

I thought about this method too, but it was a bit difficult to explain and besides, I had already suggested using a string rather than 4 longs. The reason for this is because VB does NOT have Unsigned Longs, which means you'll have to take in account the Sign Bit (which is a pain in the ass).

But, you said something about bitshifts (Which would surely make this way easier)? Is that in VB6 or are we talking VB.NET here?

Greets...

Richard

307Member[b][red]This message was edited by Bulgarian_VB at 2005-10-27 9:40:42[/red][/b][hr]

: Thanks for explaining it.

: I don't understand your calculation, but I do know what you are saying.

: I thought about this method too, but it was a bit difficult to explain and besides, I had already suggested using a string rather than 4 longs. The reason for this is because VB does NOT have Unsigned Longs, which means you'll have to take in account the Sign Bit (which is a pain in the ass).

:

: But, you said something about bitshifts (Which would surely make this way easier)? Is that in VB6 or are we talking VB.NET here?

:

: Greets...

: Richard

:

:

VB6 for sure. I don't know about VB.NET.

By the way ... you're looking at bits. Since you are defining operations on those bits, you don't need to care how VB interprets them. So you might as well NOT count a sign bit. Which reminds me: Not only would you have to define operations, but also define printing capabilities, that is... conversion into string. Then, you'll have the freedom to interpret the most significant bit as a sign bit, or not.

By the way .... what if at some point you need to use that large large number in a SQRT or trig function. Then you'll have a lot of trouble. Not that it's imposible, but there's a lot of work. When I think of it, actually, trig functions won't be that difficult since they are periodic, but anyway...

Hope I helped,

Nikolay Semov