473,666 Members | 2,368 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 1999
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******** *************@g 44g2000cwa.goog legroups.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.CreateIns tance 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.co m>
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
5653
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: MethodInfo mi = proxyInstance.GetType().GetMethod(methodName); object paramsArray = (object)methodParams.ToArray(typeof(object)); object result = mi.Invoke(proxyInstance, paramsArray); where methodParams is an array of parameters where the value...
7
41356
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 nmea checksum for gps data. e.g. everything between $ and * needs to be xor: $GPGSV,3,1,10,06,79,187,39,30,59,098,40,25,51,287,00,05,25,103,44* to get the checksum.
7
2320
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 computational-time-saving manner. Specifically, what I'd like to know is if there're any useful tips about writing your codes more efficiently. One such useful tip is that we can use the "switch" statement instead of multiple "if-else" statements; another is that...
7
7099
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 without strtol or s/printf function. Thanks, whatluo.
3
5677
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 would be appreciated. Thanks Rod
7
13871
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
7184
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 array index to start at 0. * As a result, must convert array from base1 to base 0.
4
8174
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 the .NET library provides the means to convert a number to a string using base-36? Thanks. --
5
4845
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. Dim Array() As Char Dim strwork As String = "76A3kj9d6" Array = strwork.ToCharArray OR
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8866
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8638
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6191
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4193
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.