Forum     

Go Back   Digit Technology Discussion Forum > Community > Tutorials
Register FAQ Calendar Mark Forums Read

Tutorials This section offers tutorials and How to's on just about anything related to computers and IT. Note: All tutorials are courtesy the posters and not verified by Digit


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 15-05-2005, 12:04 AM   #1 (permalink)
In The Zone
 
rohan's Avatar
 
Join Date: Mar 2004
Location: Bangalore
Posts: 297
Default Scripting QuickLaunch


Well, this tutorial I've made will be updated by me regularly. Recently I got addicted to Scripting thanks to MAKI, the kool scripting language and Vb. Then I thought there were many things that could very well, confuse new scripters and hence I thought this tutorial would help. Please add content to it. I will too... For today, there's one:

DataTypes: Why so many?

Let's consider numbers: Integers, Floats, Doubles, Singles and Booleans.

Integers: Any integeral number between:-2 147 483 647 to +2 147 483 648 That means no decimals EVER

Float: It is a floating point number and can hold upto 4-7 decimal places {depends upon language} A float has a mantissa and an exponent.

Double: It is a floating point number wit h double precision.

Booleans: It can either be 1 or 0 i.e True or Flase or Yes or No.

String: It is a piece of text that cannot be computed mathematically.

All these as you see are nothing but numbers. A 0 or 1 can be a boolean, it can be an integer, it can be a float, a double or even a string. But then why does it have to be assigned as a boolean? why can't an integer be signed as a float? There are two reasons for it:-

1.Computing: Let's take the exaple of two integers: 2 and 472 for ex. Let them be assigned as Strings. Then let's add the two strings. You will get 2472. What it does is 'concatenation'. It joins, rather than adding. Do the same with 'hi!' and ' Hello'. You'll get 'hi! Hello'.

Whereas if you add, them as integers you'll get '474' as the result.

2.Space: Each data-type has a specific amount of data-space assigned to it. Even if it is of a smaller size, it will take that much space. Consider your fridge.

You have about 100ml of yellow butter, 200ml of white butter and 300ml of milk. You have various containers. You have 10 100ml containers, 20 200ml containers and 15 300ml containers. The total space in your fridge is the amount of computing space available to your program OR totla available memory. Now, what would leave you with containers, that can furhter accomodate the maximum space and also make the fridge less uncluttered. You'll put the 100ml ting in the 100ml container, 200ml thing in the 200ml container and so on. You wouldn't waste a 300 mL container on a 100ml thing.

Similarly, integers have 8 bytes capacity, floats have 16 bit capacity and so on. Hence to make things effecient, you need to assign the numbers properly. Like, an integer called '21' will be computed as an integer even if it was a 'float', but why waste the other '8 bit'. Even if that much space isn't reuired by your program, it will close the space for other programs too and in high buil-up softwares', such clutters mean 'doomsday'...

[thanX]

©Rohan Prabhu
__________________
If there wasn't greed, we still would have been single-celled organisms.
rohan is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 19-05-2005, 01:26 AM   #2 (permalink)
In The Zone
 
sms_solver's Avatar
 
Join Date: Jan 2004
Location: somewhere
Posts: 420
Default

why don't you provide some of the examples
__________________
[ॐ एसएमएस॰सोल्भर ॐ]
sms_solver is offline  
Old 20-05-2005, 12:05 AM   #3 (permalink)
In The Zone
 
rohan's Avatar
 
Join Date: Mar 2004
Location: Bangalore
Posts: 297
Default

Quote:
Originally Posted by sms_solver
why don't you provide some of the examples
Sure, i would love to...

Let's take the example for a script that calculates the volume and returns the value to be displayed somewher in terms of %.

First we name the variables:

In MAKI it's:-
Global Float volRating;
Global Int volRint;
Global :source: volume;
Global :display: text;

Here, :source: can be anything, but generally it's a slider.
:display: can be anywhere the data is to be sent.

Whereas in Java the 'Global' is replaced by 'var' and so on...

Now, let us get the 'value' of volume. In MAKI it's

Code:
volRating=Volume.getPosition();
{Here, volume is referred to as a 'slider' and it's position is being given..}

Now, we need to display it:

We get the values out of 255, but we want it out of 100. So what we do is multiply it by 100 and then divide by 255:

Code:
volRating=volRating*100/255;
Here, volRating is a 'float'. It is taking upto 9 bytes, whereas a percentage value can be fitted within just 2 bytes.. So,what we do is convert it to an 'integer'

Code:
System.integerToString(volRating);
But, here volRating still takes the same place as was taken by a float because volRating was defined as a float. Hence we use the integer we defined as 'volRint'.

Code:
volRint=volRating;
But, now it's taking both the space of a float and also the space of an integer!!! So, we'll remove the Float..

Code:
volRating.delete;
Now, just by doing this, we saved upto 7 bytes...

For displaying purposes, it needs to be converted into a string. Hence, what we'll do is convert it in realtime, whereas not modify the 'volRating' integer. This is necessary as a String takes upto 16KB. That;s a lot of it..

Code:
text.setText(System.integerToString(volRint));
That's it, so you see. Had we not taken the pains to convert, our program which has such a small purpose would have clogged upto '16KB + 9 bytes' whereas we did it to only 2 bytes. So what do you think would happen to bigger programs like the OSes you're running?

©Rohan Prabhu
__________________
If there wasn't greed, we still would have been single-celled organisms.
rohan is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by chris
- by icebags
- by Tenida

Advertisement




All times are GMT +5.5. The time now is 01:44 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2