I use BC 5.02 (long is 32 bit) and I wonder if
there's any efficient code that would allow me
to left shift 64 bit values that I currently use
this way:
typedef struct {
unsigned long lsLong;
unsigned long msLong;
} b64_struct;
This struct can be changed if needed.
The least significant part can contain any value
in the 0..2^32 -1 range. The most significant
part; however, will usually be 0, but it may
cintain some smaller values, usually under 10,
though higher values (up to 2^16 -1) are possible
in theory.
The amount of shift will not be lnown in advance --
I will collect the above tuples into a 1 meg array,
figure out the minimum and maximum values, and
do the shifting based on that. Bits cannot fall into
the bitbucket.
TIA 19 2527
aurgathor wrote: I use BC 5.02 (long is 32 bit) and I wonder if there's any efficient code that would allow me to left shift 64 bit values that I currently use this way:
typedef struct { unsigned long lsLong; unsigned long msLong; } b64_struct;
Create a mask for the high order bit. This is a separate problem,
to make it clean and portable.
Test the high order bit of the high portion. If set, you have an
overflow, and it is time to barf. If not, shift that portion left.
Test the high order bit of the low portion. If set, increment the
high order portion and reset the bit. Shift that portion left.
done.
This is probably better relegated to a system dependant assembly
language routine, if you can arrange the linkage, and if it is used
enough to be a bind.
--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>
aurgathor wrote: I use BC 5.02 (long is 32 bit) and I wonder if there's any efficient code that would allow me to left shift 64 bit values that I currently use this way:
typedef struct { unsigned long lsLong; unsigned long msLong; } b64_struct;
This struct can be changed if needed.
The least significant part can contain any value in the 0..2^32 -1 range. The most significant part; however, will usually be 0, but it may cintain some smaller values, usually under 10, though higher values (up to 2^16 -1) are possible in theory.
The amount of shift will not be lnown in advance -- I will collect the above tuples into a 1 meg array, figure out the minimum and maximum values, and do the shifting based on that. Bits cannot fall into the bitbucket.
msLong is 0x87654321
lsLong is 0x12345678
Left shifted 8:
msLong is 0x65432112
lsLong is 0x34567800
Left shifted 36 more:
msLong is 0x45678000
lsLong is 0x0
/* BEGIN new.c */
#include <stdio.h>
typedef struct {
unsigned long lsLong;
unsigned long msLong;
} b64_struct;
b64_struct leftb64(b64_str uct value, int shift)
{
if (shift > 31) {
shift -= 31;
value = leftb64(value, 31);
value = leftb64(value, shift);
} else {
if (shift > 0) {
value.msLong <<= shift;
value.msLong |= value.lsLong >> 32 - shift;
value.lsLong <<= shift;
}
}
return value;
}
int main(void)
{
b64_struct value = {0x12345678, 0x87654321};
printf("msLong is 0x%lx\n", value.msLong);
printf("lsLong is 0x%lx\n", value.lsLong);
value = leftb64(value, 8);
puts("\nLeft shifted 8:");
printf("msLong is 0x%lx\n", value.msLong);
printf("lsLong is 0x%lx\n", value.lsLong);
puts("\nLeft shifted 36 more:");
value = leftb64(value, 36);
printf("msLong is 0x%lx\n", value.msLong);
printf("lsLong is 0x%lx\n", value.lsLong);
return 0;
}
/* END new.c */
--
pete
aurgathor wrote: I use BC 5.02 (long is 32 bit) and I wonder if there's any efficient code that would allow me to left shift 64 bit values that I currently use this way:
typedef struct { unsigned long lsLong; unsigned long msLong; } b64_struct;
Step 0: See whether you can use `unsigned long long' (a
type introduced by C99, but supported as an extension even by
some C90 compilers when operated in lenient modes).
Step 1: Follow the KISS[*] principle, and use
b64_struct x = { ... };
int bits = ...;
x.msLong = (x.msLong << bits) | (x.lsLong >> (32 - bits));
x.lsLong <<= bits;
[*] "Keep It Simple, Stupid!"
Step 2: Try something else. Step 2 is only to be taken if
Steps 0 and 1 don't pan out. Some possible reasons they might not:
.... until and unless this proves to be inadequate. A few
potential reasons for inadequacy:
- Too slow (but you won't know this until you actually
measure it, in the context of the entire program)
- `long long' available only on some but not all of the
systems of interest
- On some systems `long' is wider than 32 bits (easy to
re-spell 32, but you need to decide what to do about
bits 64 and upwards)
- Can only shift by 0 <= bits < 32 (could wrap the above
in a loop if that's a problem)
Step 3: Re-read the subject line. Was it prompted by, er,
any extreme difficulty in getting the code out?
--
Eric Sosman es*****@acm-dot-org.invalid
"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message
news:87******** ****@benpfaff.o rg... We'd really appreciate it if you'd keep that kind of language out of the headers...
Given that :
1) he didn't use "that kind of language" in his message
2) that f & t use the same finger on QWERTY keyboards
3) it's a common "Freudian slip"
how could you honestly believe it was intentional? I think you rushed to
judgement here.
Rod Pemberton
Rod Pemberton wrote: "Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message news:87******** ****@benpfaff.o rg... We'd really appreciate it if you'd keep that kind of language out of the headers...
Given that :
1) he didn't use "that kind of language" in his message 2) that f & t use the same finger on QWERTY keyboards 3) it's a common "Freudian slip"
how could you honestly believe it was intentional? I think you rushed to judgement here.
Just a quick hint here - try looking up the word "humor".
<en******@yahoo .com> wrote in message
news:11******** *************@j 33g2000cwa.goog legroups.com... Rod Pemberton wrote: "Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message news:87******** ****@benpfaff.o rg... We'd really appreciate it if you'd keep that kind of language out of the headers...
Given that :
1) he didn't use "that kind of language" in his message 2) that f & t use the same finger on QWERTY keyboards 3) it's a common "Freudian slip"
how could you honestly believe it was intentional? I think you rushed
to judgement here.
Just a quick hint here - try looking up the word "humor".
There was nothing humorous in what he said and there was nothing, such as a
smiley, to indicate that it was humor. I also assumed that since he didn't
post a response to the OP's question, he was offended. That seems to be the
usual case with Pfaff. I also assumed that since he was posting from a
university email, that his school is filtering, flaging, and reviewing his
email for foul language. Do you think my assumptions are invalid?
Rod Pemberton
Rod Pemberton wrote: <en******@yahoo .com> wrote in message news:11******** *************@j 33g2000cwa.goog legroups.com... Rod Pemberton wrote: "Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message news:87******** ****@benpfaff.o rg... We'd really appreciate it if you'd keep that kind of language out of the headers... Given that :
1) he didn't use "that kind of language" in his message 2) that f & t use the same finger on QWERTY keyboards 3) it's a common "Freudian slip"
how could you honestly believe it was intentional? I think you rushed to judgement here. Just a quick hint here - try looking up the word "humor".
There was nothing humorous in what he said and there was nothing, such as a smiley, to indicate that it was humor. I also assumed that since he didn't post a response to the OP's question, he was offended. That seems to be the usual case with Pfaff. I also assumed that since he was posting from a university email, that his school is filtering, flaging, and reviewing his email for foul language. Do you think my assumptions are invalid?
Rod Pemberton
Rod,
Ben Pfaff is well known here and is a friend. He is a graduate student
in a CS PhD program at Stanford University at Palo Alto. I bet he knows
how to spell 'flagging'.
We've known Ben for years. You have come to us only recently. I
personally don't care what assumptions you draw about Ben but you might
consider keeping the negative ones to yourself.
I find your posts to other groups, c.o.m.djgpp for example, helpful and
friendly. Here in comp.lang.c you are a PITA. What gives?
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
"Joe Wright" <jo********@com cast.net> wrote in message
news:MO******** ************@co mcast.com... Rod Pemberton wrote: <en******@yahoo .com> wrote in message news:11******** *************@j 33g2000cwa.goog legroups.com... Rod Pemberton wrote: "Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message news:87******** ****@benpfaff.o rg... > We'd really appreciate it if you'd keep that kind of language out > of the headers... Given that :
1) he didn't use "that kind of language" in his message 2) that f & t use the same finger on QWERTY keyboards 3) it's a common "Freudian slip"
how could you honestly believe it was intentional? I think you rushed to judgement here. Just a quick hint here - try looking up the word "humor".
There was nothing humorous in what he said and there was nothing, such
as a smiley, to indicate that it was humor. I also assumed that since he
didn't post a response to the OP's question, he was offended. That seems to be
the usual case with Pfaff. I also assumed that since he was posting from a university email, that his school is filtering, flaging, and reviewing
his email for foul language. Do you think my assumptions are invalid?
Ben Pfaff is well known here and is a friend. He is a graduate student in a CS PhD program at Stanford University at Palo Alto. I bet he knows how to spell 'flagging'.
I don't use a spell checker. You're likely to find occasional misspellings,
rare or alternate spellings, and maybe even a antonym or two in my posts.
We've known Ben for years. You have come to us only recently.
Recently? No. Whether my posts made it to Google or only a few select
servers is a different issue...
I personally don't care what assumptions you draw about Ben but you might consider keeping the negative ones to yourself.
Did I make a negative comment about Pfaff? I don't see one. Nor, do I see
an untrue one. I see two possible non-negative assumptions. It appears to
me he rushed to judgement. There has been no further clarification from
him.
I find your posts to other groups, c.o.m.djgpp for example, helpful and friendly. Here in comp.lang.c you are a PITA. What gives?
There are a large number of assholes, frauds, and charlatans here. I'm
dealing with them appropriately. However, in this thread, as far as I can
tell, I've done none of that.
Rod Pemberton This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tina Li |
last post by:
Hello,
I've been struggling with a regular expression for parsing XML files, which keeps giving the run time error "maximum
recursion limit exceeded". Here is the pattern string:
r'<code>(?P<c>.*?)</code>.*?<targetSeq
name="(?P<tn>.*?)">.*?<target>(?P<t>.*?)</target>.*?<align>(?P<a>.*?)</align>.*?<template>(?P<temp>.*?)</template>.*?<an
otherTag>(?P<at>.*?)</anotherTag>.*?<yetAnotherTag>(?P<yat>.*?)</yetAnotherTag>'
The file format...
|
by: jrlen balane |
last post by:
basically what the code does is transmit data to a hardware and then
receive data that the hardware will transmit.
import serial
import string
import time
from struct import *
ser = serial.Serial()
|
by: John Cho |
last post by:
// CHO, JOHN
#include<iostream>
class fracpri{
int whole;
int numer;
int denom;
|
by: netsurfer |
last post by:
Hi:
I am working on a project and need assistance, and would really
appreciate any feedback on it.
First part I'm banging my head against the wall on is about the amounts
of the Amount fields along the right to automatically equal the PETTY
CASH SUB-TOTAL field. So, the amount in this PETTY CASH SUB-TOTAL
field comes up automatically. Also, I need to have the amount in the
TOTAL AMOUNT field come up automatically as being the sum of...
|
by: mitsura |
last post by:
Hi,
I have included a small listing. The test program opens a panel and
show a bitmap.
What I want is to when the mouse is over the bitmap panel, I want to
trap the left mouse click.
The purpose is to get the position of the mouse pointer on the bitmap.
However, for some reason, the left (I also tried right) mouse clicks
are not intercepted.
I new to Python and wxWindows so any help would be greatly appreciated.
| |
by: ethanmys |
last post by:
hello everyone. hours ago i found a topic about solving the problem:
find out 2 int between certain rang, say 1---100, both the 2 int's sum
and minus should be a int's square.
i write this piece of code and i want you to give some advice. can the
code run quicker? i think there must exist many quicker ones.
/*
this doucument and source code belong to Ethan Mys, oct 30, 2005.
any modification to improve the source code is welcome.
you can...
|
by: nessuno |
last post by:
I can't find any discussion of this question in this NG.
I'd like to implement some variable precision integer arithmetic in C,
and do it efficiently. A problem arises with the divide/remainder
operations. I'm using gcc on x86, but a lot of what I say applies to
other architectures.
First, I assume the div and ldiv functions are more efficient than
using / and % (obviously it depends on the compiler and level of
optimization, but...
|
by: Brian Wotherspoon |
last post by:
I have a table with data that is refreshed regularly but I still need to
store the old data. I have created a seperate table with a foreign key
to the table and the date on which it was replaced. I'm looking for an
efficient way to select only the active data.
Currently I use:
SELECT ...
FROM DataTable AS D
LEFT OUTER JOIN InactiveTable AS I ON I.Key = D.Key
|
by: tomwolfstein |
last post by:
Hi.
I am trying to write a wrapper for the standard VC1 decoder, and I need to resolve a "TypeLoadException"
The decoder comes an an executable which I've turned into a .dll. This decoder has about a ton of structures, most of the containing other structures, arrays of structures, and unions of structures.
I need help converting the following to managed code:
The unmanaged structure is this:
typedef struct
{
vc1_eBlkType eBlkType; /**...
|
by: Madhur |
last post by:
I would like to know the best efficient way to shift a flat buffer by
say 4bits.
for exaple if the flat buffer is
0x62 0x48 0x23 ....
then the result should be
0x06 0x24 0x82 0x3.....
|
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...
| |
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: 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: 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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |