BrainDump
  Home arrow BrainDump arrow Page 2 - Understanding Numeric Data in VBScript
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

Understanding Numeric Data in VBScript
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-02-26

    Table of Contents:
  • Understanding Numeric Data in VBScript
  • Numeric Subtypes and Precision
  • Number systems
  • Conversion Functions
  • Converting data types

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Understanding Numeric Data in VBScript - Numeric Subtypes and Precision


    (Page 2 of 5 )

    Numeric data subtypes represent different levels of precision in these numbers and also control the precision of the numbers that are the result of VBScript’s calculations.  Each data subtype allocates a specific amount of memory for a number.  Thus, the precision of some numbers can become limited by the amount of memory available to them.  Let’s take a look at the numeric subtypes.

    Fixed width numeric subtypes

    Type

    Precision

    Data Range

    Byte

    1 byte

    0-255

    Integer

    2 bytes

    -32,768 to 32,767

    Long

    4 bytes

    -2,147,483,648 to 2,147,483,647

       

    Floating point numeric subtypes

    Single

    4 bytes

    -3.402823E38 to -1.401298E-45 for negative values;

    1.401298E-45 to 3.402823E38 for positive values

    Double

    8 bytes

    -1.79769313486232E308 to -4.94065645841247E-324 for negative values;

    4.94065645841247E-324 to 1.79769313486232E308 for positive values

    As you can see, the precision of each data subtype affects the respective data range dramatically.  Let’s try to understand exactly what these precisions are and how they affect those ranges.

    VBScript also provides two other special numeric types: Date and Currency.  Date is a numeric representation of any valid date and Currency is used to force currency calculations.

    Computer processors do not actually understand numbers.  They work with bit patterns.  Think of a bit as a switch that is either on or off, true or false. These bits are combined as strings, known as patterns, to indicate different values.  These values are commonly represented as numbers with 0 being on, or true, and 1 being off, or false.

    A bit represents a single, two value quantity like: on or off, true or false, 0 or 1.

    Bit patterns, then, are combinations of bits.  Here are some examples of patterns that can be constructed.

    • A single bit has two states: either T or F. (21 possibilities)
    • Two bits can distinguish between four states: TT, TF, FT, FF (22 possibilities)
    • Three bits can distinguish between eight states: TTT, TTF, TFT, FTT, FFT, FTF, TFF, FFF. (23 possibilities)

    As you can see, a bit pattern’s length is very important. The number of possible values for a bit pattern containing a given width is equal to 2n where n represents the number of bits in the pattern.  This range is known as a pattern’s width.

    Therefore, a bit pattern containing 10 bits would have a width of 210 or 1024 possibilities.

    Computer storage is typically stated in bytes.  A byte consists of eight bits.  Using the formula above you can see that a byte has 28 or 256 possibilities.  Thus, the Byte data type, with a precision of a single byte, has 256 possibilities.  That’s why its range is 0-255.  Remember that 0 is a state and that the Byte type only uses positive numbers.

    Here again, the Integer type has a width of two bytes. (Remember that 2 bytes equals 16 total bits.)  That means 216 or 65536 possibilities.  Since the Integer type allows both positive and negative numbers, divide that by two—half in each direction.  Thus you get 32,768 negative possibilities and 32,758 positive possibilities.  The 0 state is considered a positive.

    So, the Integer type has 32,768 negative possibilities, 0, and 32,757 positive possibilities greater than 0.  In other words, its range is any integer between -32,768 and 32,757 including zero.

    The floating point ranges are calculated in the same manner, however, there are bits used for the decimal point, so the ranges seem a bit limited compared to their fixed width counterparts.

    More BrainDump Articles
    More By Nilpo


     

    BRAINDUMP ARTICLES

    - Introduction to Office Live Workspace
    - Using MS Excel for One-way Analysis of Varia...
    - Comparing Data Sets Using Statistical Analys...
    - Import Blogger Posts into WordPress Using Wi...
    - Download WordPress from an FTP Server and Ru...
    - Install and Run WordPress in XAMPP Local Host
    - What Windows 7 Brings to the Table
    - Virtualization and Sandbox Detection
    - Advanced Firebug Techniques in Windows XP Ho...
    - Editing CSS with Firebug in Windows XP Home
    - Using Firebug in Windows XP Home
    - Migrating to Exchange Server 2007
    - Using System Restore on a Non-Bootable PC
    - Finding Logged on Users and More Scripting S...
    - Developing Macro Commands in MS Excel





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT