What would be the most efficient way to calculate the two's complement
of a variable length byte array?
Thanks for your time.
Feb 10 '07
14 10514
On Feb 16, 11:44 pm, "Bruce Wood" <brucew...@cana da.comwrote:
On Feb 16, 8:54 pm, darthgha...@gma il.com wrote:
So what you are all saying is that there is no easy way to get a two's
complement of a byte array? That sucks. I guess that's Microsoft's
gift to me?
I don't know if it's particularly _Microsoft's_ gift to you. More like
the modern Intel processor's gift to you. In fact, I don't think I've
ever worked on a language or a processor in which something as obscure
as taking the two's-complement of a byte array was optimized into some
special instruction or operation.
There's certainly an _easy_ way to do it: loop through the bytes and
take the two's complement of each one. That's pretty darned easy.
However, what you asked for was _faster_. As I said, I've never seen a
_fast_, short-cut way to do that, on any platform, on any chip.
Perhaps others with wider experience have, but not me.
Thanks for the response. That was the way I was hoping to avoid.
Looks like it's the best bet.
Thanks again for the time.
Chris
On Feb 17, 12:16 am, darthgha...@gma il.com wrote:
On Feb 16, 11:44 pm, "Bruce Wood" <brucew...@cana da.comwrote:
On Feb 16, 8:54 pm, darthgha...@gma il.com wrote:
So what you are all saying is that there is no easy way to get a two's
complement of a byte array? That sucks. I guess that's Microsoft's
gift to me?
I don't know if it's particularly _Microsoft's_ gift to you. More like
the modern Intel processor's gift to you. In fact, I don't think I've
ever worked on a language or a processor in which something as obscure
as taking the two's-complement of a byte array was optimized into some
special instruction or operation.
There's certainly an _easy_ way to do it: loop through the bytes and
take the two's complement of each one. That's pretty darned easy.
However, what you asked for was _faster_. As I said, I've never seen a
_fast_, short-cut way to do that, on any platform, on any chip.
Perhaps others with wider experience have, but not me.
Thanks for the response. That was the way I was hoping to avoid.
Looks like it's the best bet.
Thanks again for the time.
Chris
Looks like the newest version of Visual Studio will come with a
BigInteger class that I could use. It doesn't support bitwise right
now, but may be they will add it later.
Here's where I saw that: http://blogs.msdn.com/bclteam/archiv...bar-gazit.aspx
On Feb 20, 8:25 pm, darthgha...@gma il.com wrote:
On Feb 17, 12:16 am, darthgha...@gma il.com wrote:
On Feb 16, 11:44 pm, "Bruce Wood" <brucew...@cana da.comwrote:
On Feb 16, 8:54 pm, darthgha...@gma il.com wrote:
So what you are all saying is that there is no easy way to get a two's
complement of a byte array? That sucks. I guess that's Microsoft's
gift to me?
I don't know if it's particularly _Microsoft's_ gift to you. More like
the modern Intel processor's gift to you. In fact, I don't think I've
ever worked on a language or a processor in which something as obscure
as taking the two's-complement of a byte array was optimized into some
special instruction or operation.
There's certainly an _easy_ way to do it: loop through the bytes and
take the two's complement of each one. That's pretty darned easy.
However, what you asked for was _faster_. As I said, I've never seen a
_fast_, short-cut way to do that, on any platform, on any chip.
Perhaps others with wider experience have, but not me.
Thanks for the response. That was the way I was hoping to avoid.
Looks like it's the best bet.
Thanks again for the time.
Chris
Looks like the newest version of Visual Studio will come with a
BigInteger class that I could use. It doesn't support bitwise right
now, but may be they will add it later.
Here's where I saw that:http://blogs.msdn.com/bclteam/archiv...ucing-system-n...
Sorry... still won't work. Again, if you want ones-complement then
this is fine. If you want twos-complement then it won't fly: you have
to take twos-complement byte by byte.
"Bruce Wood" <br*******@cana da.comwrote in message
news:11******** **************@ j27g2000cwj.goo glegroups.com.. .
On Feb 16, 8:54 pm, darthgha...@gma il.com wrote:
>So what you are all saying is that there is no easy way to get a two's complement of a byte array? That sucks. I guess that's Microsoft's gift to me?
I don't know if it's particularly _Microsoft's_ gift to you. More like
the modern Intel processor's gift to you. In fact, I don't think I've
ever worked on a language or a processor in which something as obscure
as taking the two's-complement of a byte array was optimized into some
special instruction or operation.
PSUBSB? http://asm.inightmare.org/opcodelst/index.php?op=PSUBSB
>
There's certainly an _easy_ way to do it: loop through the bytes and
take the two's complement of each one. That's pretty darned easy.
However, what you asked for was _faster_. As I said, I've never seen a
_fast_, short-cut way to do that, on any platform, on any chip.
Perhaps others with wider experience have, but not me.
"Ben Voigt" <rb*@nospam.nos pamwrote in message
news:uA******** ******@TK2MSFTN GP04.phx.gbl...
>
"Bruce Wood" <br*******@cana da.comwrote in message
news:11******** **************@ j27g2000cwj.goo glegroups.com.. .
>On Feb 16, 8:54 pm, darthgha...@gma il.com wrote:
>>So what you are all saying is that there is no easy way to get a two's complement of a byte array? That sucks. I guess that's Microsoft's gift to me?
I don't know if it's particularly _Microsoft's_ gift to you. More like the modern Intel processor's gift to you. In fact, I don't think I've ever worked on a language or a processor in which something as obscure as taking the two's-complement of a byte array was optimized into some special instruction or operation.
PSUBSB?
http://asm.inightmare.org/opcodelst/index.php?op=PSUBSB
Sorry, if you want true two's-complement, don't use non-saturating PSUBB http://asm.inightmare.org/opcodelst/index.php?op=PSUBB
If you want arithmetic negation, PSUBSB more likely serves your purpose. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tor Erik Sønvisen |
last post by:
Hi
I need a time and space efficient way of storing up to 6 million bits. Time
efficency is more important then space efficency as I'm going to do searches
through the bit-set.
regards tores
|
by: Thomas Paul Diffenbach |
last post by:
I'm trying to write a space efficient string (nul terminated array
of char), storing the characters directly unless the number of
characters is too large to be so stored, and storing a pointer to
other storage otherwise.
Rather than lose space to padding by just using a sentinal bool to
indicate which member of the union has been written to, I want to
overload the last character of the directly stored string as the
sentinal.
|
by: Greenhorn |
last post by:
Hi,
Is two's complement always used as a storage method or is it computed
while computing the expression involved.
e.g., int a = -2, b = 3, c = 4, d;
d = b - c;
Here, is 'a' stored as two's complement of '2'?
or
is '-c' (two's complement of c) computed on the fly and the resulting
value is added to b ( b + (-c))?
|
by: Ted Miller |
last post by:
Hi folks,
I've got an unmanaged routine I'm pinvoking to. It takes a pointer to an
array of 3 pointers to bytes, typed as byte**.
public static extern void foo(byte **p3pb);
unsafe {
byte pB = new byte;
|
by: José Joye |
last post by:
I have to compare 2 byte and I must be sure that they are fully identic.
I have to perform this check about 1000 times per minute and on arrays that
are between 100-200K in size.
In that sense, what is the most efficient method?
Sincerely,
José
| |
by: Marc |
last post by:
I'm trying to set the first three bits to zero on a byte. For some reason,
the compiler is casting the number peculiarly when I use the bitwise
complement operator.
Here's what I think should work but doesn't:
byteArray &= ~0xe0; // set the first three bits to 0 (11100000 == 0xe0)
The error is "Constant value '-225' cannot be converted to a 'byte'".
|
by: KK |
last post by:
/* Target - read an integer from a binary file */
unsigned int Byte2Int(char *buff)
{
unsigned char* byte = reinterpret_cast<unsigned char*> (buff);
return ((byte<<24)|(byte<<16)|(byte<<8)|(byte));
}
/* part of main funciton */
ifstream fp("in.bin",ios::binary);
char buff;
|
by: chris |
last post by:
I have a few byte arrays that I would like to combine into one array
(order needs to be kept). What would be the most efficient way to do
this?
Thanks for your time,
Chris
|
by: |
last post by:
Hi all,
I want to create a method that does the following:
1) Programmatically instantiate a new XmlDataSource control
2) For each file in a named directory, make a "FileSystemItem" element
3) On each FileSystemItem Element, make two child nodes, one with the file
name, one with the file size. ie.
<filesystemitems>
<filesystemitem>
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |