## Table of Contents

# Overview / Survival Guide

The other day I was thinking about the many forum examples(including ones that I have provided) where it would appear that memory consumption may have not been taken into consideration. In .NET (Visual Basic & C#), there are several numeric data types out there for you to use, but which one should you choose? This article is meant to help you select a numeric data type that best fills your needs, while also balancing outperformance with possible data storage concerns.

# Binary Data

In computer science, it is a well-known fact that the easiest way for a computer to process data is using a base 2 numbering system known as the binary numbering system. The reason that the binary numbering system is the easiest way for a computer to process base two numbers is that ones and zeros can be represented with either a high or a low voltage state. For example, a one can be represented typically with 5 volts, whereas zero is represented with 0 volts. The image below shows how one might represent the number 85 with a binary signal.

# Data Sizes

One might be able to gain some insight on to how valuable paying attention to data sizes might be in the long run by taking a look at a visual representation of data sizes. In the below image, you can see how larger data types can quickly consume more resources than smaller datatypes. In iteration, this can potentially consume great quantities of storage space.

# A rough guideline for data type selection...

## What are you using the numeric data type for?

Will this variable require the use of fractional numbers (non-whole rational numbers)?

### No fractional numbers

Which range will this variable stay within?

- If 0 to 255 then choose
**Byte**(8 Bit) - If 0 to 65535 then choose
**UInt16**/**UShort**(2 Bytes/16 Bit) - If 0 to 4294967295 then choose :
**UInt32**/**UInteger**(4 Bytes/32 Bit) - If 0 to 18446744073709551615 then choose
**UInt64**/**ULong**(8 Bytes/64 Bit) - If -32768 to 32767 then choose
**Int16**/**Short**(2 Bytes/16 Bit) - If -2147483648 to 2147483647 then choose
**Int32**/**Integer**(4 Bytes/32 Bit) - If -9223372036854775808 to 9223372036854775807 then choose
**Int64**/**Long**(8 Bytes/64 Bit)

### With fractional numbers

What's more important?

- If
**Memory Usage**then choose**Single**(4 Bytes/32 bit) - If
**Accuracy**(twice as precise as a single) &**Memory Usage**then choose Double (8 Bytes/64 bit) - If You Require
**Absolute Accuracy,**then choose Decimal (16 bytes/128 bit)

**Summary**

At declaration, taking extra consideration into selecting a numeric datatype may be beneficial, and help to reduce unnecessary memory consumption.

# See also

Please check out my other TechNet Wiki articles!