473,513 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

when to use smaller integers like byte or short rather than INTEGER

If I have a loop that has a max value of say 20 why would I not want to
define the loop counter using a BYTE or SHORT as opposed to a INTEGER.

It seems in most books or samples they define fairly small numbers as
INTEGER.

thanks, David
Jan 2 '08 #1
3 1629
On 2008-01-02, David <ch**************@yeehee.cwrote:
If I have a loop that has a max value of say 20 why would I not want to
define the loop counter using a BYTE or SHORT as opposed to a INTEGER.

It seems in most books or samples they define fairly small numbers as
INTEGER.

thanks, David
You know it probably doesn't really matter - but, at least in the old
days using a 32-bit loop counter would give you a slightly better
performing loop :) Simply because it was the native word size of the
processor.

--
Tom Shelton
Jan 2 '08 #2
"David" <ch**************@yeehee.cschrieb:
If I have a loop that has a max value of say 20 why would I not want to
define the loop counter using a BYTE or SHORT as opposed to a INTEGER.

It seems in most books or samples they define fairly small numbers as
INTEGER.
'Integer' is IMO the natural choice. Note that bounds may change over time.
The range of 'Integer' is large enough for common scenarios. In addition,
'Integer' as a 32-bit data type is very suitable for 32-bit computers. Most
classes in the .NET Framework use 'Integer' for indices. Using other types
may require (implicit widening) type conversions.

However, 'Byte and 'Short' are not entirely useless. They are often
required in p/invoke scenarios and when reading binary data from streams
(files, network streams, etc.). Arrays of 'Byte' are typically used to
store raw binary data.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 3 '08 #3
David,

The smaller numbers are in my idea only suitable as they are used in old
databases or DLL's.

Be aware that in a 64bit computer the Int64 is probably the best. In past
the Integer was the type that was most suitable to the in those days most
used processor. A strong loby from old Microsoft Developing tool users (in
my idea VB6) has changed that and fixed it to 32Bits for the future.

This means that in fact the Integer will become in future proabably
everytime more outdated now that it is fixed to the 32Bit computer. (It is
not very bad, it uses only (ProcessorBits/IntBits * cycles) instead of 1 and
mostly has a new computer enough cycles to hide this for you).

Cor

Jan 3 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3460
by: rusttree | last post by:
I'm working on a program that manipulates bmp files. I know the offset location of each piece of relevent data within the bmp file. For example, I know the 18th through 21st byte is an integer...
87
3239
by: j0mbolar | last post by:
I've read in the standard that addresses basically can't be interpreted as integers. If they can, it is implementation defined behavior. However, if they can't be viewed as integers in any sense...
20
5318
by: Hanzac Chen | last post by:
Hi, I don't understand why this could happen? The Code 1 will output `fff9' and the Code 2 will output `1' How could the `mod 8' not have effect? /* Code 1 */ #include <stdio.h> #include...
4
2403
by: Dennis Myrén | last post by:
Hi. Is there a way to utilize the great primitive data type formatting routines available in .NET without working with strings? I want a byte directly rather than a string. I think it is...
8
14351
by: Nik Martin | last post by:
If I receive a message from the .net sockets class, it's a byte array. The original message is an ASCII string,like "70,70,70,70,70,0,0,0,0". The commas here represent individual bytes. The 70's...
4
1653
by: John A Grandy | last post by:
could someone explain the following to me : Appending the literal type character I to a literal forces it to the Integer data type. Appending the identifier type character % to any identifier...
2
3365
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
11
2210
by: cmdolcet69 | last post by:
Public Shared adc_value As word_byte Public Class byte_low_hi Public low_byte As Byte Public high_byte As Byte End Class pmsg(2) = CChar(adc_value.word16.high_byte)
42
2007
by: lorlarz | last post by:
Contrary to what one authority in the JavaScript field says: JavaScript does make errors when dealing with just with integers. This authority (Douglas Crockford.) says: "integer arithmetic in...
0
7257
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.