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

- 140.8K All Categories
- 104.4K Programming Languages
- 6.4K Assembler Developer
- 1.8K Basic
- 39.7K C and C++
- 4.2K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.6K Java
- 4.1K Pascal
- 1.3K Perl
- 1.9K PHP
- 506 Python
- 48 Ruby
- 4.3K VB.NET
- 1.6K VBA
- 20.8K Visual Basic
- 2.6K Game programming
- 310 Console programming
- 88 DirectX Game dev
- 1 Minecraft
- 109 Newbie Game Programmers
- 2 Oculus Rift
- 8.9K Applications
- 1.8K Computer Graphics
- 726 Computer Hardware
- 3.4K Database & SQL
- 521 Electronics development
- 1.6K Matlab
- 627 Sound & Music
- 254 XML Development
- 3.3K Classifieds
- 191 Co-operative Projects
- 180 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
- 3K Miscellaneous
- 3 Join the Team
- 2 User Profiles
- 353 Comments on this site
- 60 Computer Emulators
- 1.8K General programming
- 178 New programming languages
- 608 Off topic board
- 167 Mobile & Wireless
- 41 Android
- 124 Palm Pilot
- 335 Multimedia
- 151 Demo programming
- 184 MP3 programming
- 0 Bash scripts
- 17 Cloud Computing
- 52 FreeBSD
- 1.7K LINUX programming
- 366 MS-DOS
- 0 Shell scripting
- 320 Windows CE & Pocket PC
- 4.1K Windows programming
- 887 Software Development
- 405 Algorithms
- 67 Object Orientation
- 85 Project Management
- 88 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
- 285 WEB Servers
- 116 WEB-Services / SOAP

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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. (;->

About & Contact / 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-2013 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

- Spam

0 · Vote Down Vote Up · Share on Facebook54MemberLike 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. (;->

- Spam

0 · Vote Down Vote Up · Share on Facebook2,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

- Spam

0 · Vote Down Vote Up · Share on Facebook54MemberThanks 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. (;->

- Spam

0 · Vote Down Vote Up · Share on Facebook2,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]

- Spam

0 · Vote Down Vote Up · Share on Facebook54MemberAgain 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. (;->

- Spam

0 · Vote Down Vote Up · Share on Facebook2,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

- Spam

0 · Vote Down Vote Up · Share on Facebook307Member: 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

- Spam

0 · Vote Down Vote Up · Share on Facebook2,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

- Spam

0 · Vote Down Vote Up · Share on Facebook307Member[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

- Spam

0 · Vote Down Vote Up · Share on Facebook