473,506 Members | 17,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Efficiently convert Base 1 Array to Base 0 Array?

Hi all,

My scenario is as follows:

* Receive a base 1 array (index starts at 1 instead of 0) of data from
a COM component .
* Need to pass this array to a .net component that requires its array
index to start at 0.
* As a result, must convert array from base1 to base 0.

Currently my solution for this is to create a new array and copy the
contents of is as follows:
* Create new based 0 array
* Copy the content of base 1 array to new array by 1)iterating through
each element in base 1 array and 2)doing assignment to base 0 array.
* Assign new array to array used by .net component described above.

My question is as follows:
Is there a quicker way to convert a base1 array to base0 without
having to do iteration and assignment? Does something in the .net
framework already do this?

Thanks,
Peter
www.nofelt.com

Feb 8 '06 #1
5 1986
Peter Nofelt wrote:
* Receive a base 1 array (index starts at 1 instead of 0) of data from
a COM component .
* Need to pass this array to a .net component that requires its array
index to start at 0.
* As a result, must convert array from base1 to base 0.
The indexes are not passed with the array. When the array is received
from the COM component, its first element should be referred to with
index 0 in .Net.

Does the array have an *empty* element at index 0 when you get it in
..Net?

Currently my solution for this is to create a new array and copy the
contents of is as follows:
* Create new based 0 array
* Copy the content of base 1 array to new array by 1)iterating through
There is no such thing as a "0 based array" or a "1 based array" unless
I am missing something. When you receive the array in .Net, addressing
the element with index 0 should be the first element in the array. You
should not have to convert anything. Unless the array as received from
COM has an *empty* element at index 0.
My question is as follows:
Is there a quicker way to convert a base1 array to base0 without
having to do iteration and assignment? Does something in the .net
framework already do this?


You shouldn't have to do anything. Someone please enlighten me if I am
wrong.

Feb 8 '06 #2
The usual problem is that while the array is just a contiguous section of
memory and so there is no idea of whether the first element has index 0 or 1
or something else, the algorithms where the array is used does have a
preference.

See http://www.library.cornell.edu/nr/bookcpdf/c1-2.pdf for the Numerical
Recipes in C discussion of this, and a solution in C.

Chuck Gantz
"Chris Dunaway" <du******@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Peter Nofelt wrote:
* Receive a base 1 array (index starts at 1 instead of 0) of data from
a COM component .
* Need to pass this array to a .net component that requires its array
index to start at 0.
* As a result, must convert array from base1 to base 0.


The indexes are not passed with the array. When the array is received
from the COM component, its first element should be referred to with
index 0 in .Net.

Does the array have an *empty* element at index 0 when you get it in
.Net?

Currently my solution for this is to create a new array and copy the
contents of is as follows:
* Create new based 0 array
* Copy the content of base 1 array to new array by 1)iterating through


There is no such thing as a "0 based array" or a "1 based array" unless
I am missing something. When you receive the array in .Net, addressing
the element with index 0 should be the first element in the array. You
should not have to convert anything. Unless the array as received from
COM has an *empty* element at index 0.
My question is as follows:
Is there a quicker way to convert a base1 array to base0 without
having to do iteration and assignment? Does something in the .net
framework already do this?


You shouldn't have to do anything. Someone please enlighten me if I am
wrong.

Feb 8 '06 #3
Chris Dunaway <du******@gmail.com> wrote:
Currently my solution for this is to create a new array and copy the
contents of is as follows:
* Create new based 0 array
* Copy the content of base 1 array to new array by 1)iterating through


There is no such thing as a "0 based array" or a "1 based array" unless
I am missing something. When you receive the array in .Net, addressing
the element with index 0 should be the first element in the array. You
should not have to convert anything. Unless the array as received from
COM has an *empty* element at index 0.


..NET itself certainly *does* have non-zero based arrays. Look at the
various overloads to Array.CreateInstance for details. C# won't let you
use a non-zero based single dimensional array as MyType[] but it will
let you use multi-dimensional arrays as MyType[,] etc whatever their
bases are.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 8 '06 #4
Agreed, but his COM component isn't returning an algorithm. It's
returning an array. Whether or the COM component accessed the array
using 1 or 0 as the base index is irrelevant. Once it gets to the .Net
side, he can use 0 based indexing without having to convert the array
further.

I guess if the index had some significance to the actual data stored in
the array, he might have to make appropriate adjustments, but for just
accessing the elements of the array, he should be able to start with
index 0.

Feb 8 '06 #5
Yes, but whatever the base is, its just making a calculation to find
the offset in the array for that index. If the COM control is
returning an array, the 'base' of the array is not returned. The op
should be able to just use standard '0 based' indexes to refer to the
elements in the array.

Feb 8 '06 #6

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

Similar topics

1
5629
by: phancey | last post by:
I am trying to invoke a web service method dynamically. I have created a generic function that takes a method name, string of parameters and calls the web method using System.Reflection: ...
7
41318
by: Philipp H. Mohr | last post by:
Hello, I am trying to xor the byte representation of every char in a string with its predecessor. But I don't know how to convert a char into its byte representation. This is to calculate the...
7
2315
by: eyh5 | last post by:
Hi, I'm writing some C codes to run simulations. I'm wondering if there is a website that may contain useful information on how to make one's code run more efficiently and in a...
7
7075
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done...
3
5623
by: Rodusa | last post by:
I am looking for an example of how to save a DataTable into Base64 and vice-versa. I tried using Convert.ToBase64String(), but it says that it cannot convert DataTable to byte. Any help or pointing...
7
13862
by: henrytcy | last post by:
Hi, How can I convert integer, for example 12113, to char array but without specify an array size in C programming? Thanks!
9
7173
by: AtariPete | last post by:
Hi all, My scenario is as follows: * Receive a base 1 array (index starts at 1 instead of 0) of data from a COM component . * Need to pass this array to a .net component that requires its...
4
8145
by: Jonathan Wood | last post by:
Does anyone know why the toBase argument in Convert.ToString() is limited to 2, 8, 10, or 16? It takes virtually the same code to support all base values from 2 to 36. And can anyone tell me if...
5
4819
by: da1978 | last post by:
Hi experts, I need to convert a string or a Byte array to a string byte array. Its relatively easy to convert a string to an char array or a byte array but not a STRING byte array. i.e. ...
0
7220
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
7308
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
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5617
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,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
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
3188
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
410
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.