T
Triple-DES
Except if u is an even multiple of 65536.
Hmm...that's interesting. Did I make a grammatical error, or isn't
that exactly what I wrote?
Except if u is an even multiple of 65536.
Triple-DES said:Hmm...that's interesting. Did I make a grammatical error, or isn't
that exactly what I wrote?
Triple-DES schrieb:
That's exactly what you wrote except the word "even".
But odd multiples do as well:
(65536 & 32768) is 0, and (65536 % 32768) is also 0.
Okay, if I use 32767 as a value instead or or'ing 1<<i, there should be
no problem.
But in that case 11111111000000001111111111111111 would be
2^24-1.
But would
unsigned long two_to_the_24th_minus_1()
{
unsigned long i(0);
for (int j=0;j<24;++j)
i|=(1<<j);
return i;
}
return 16777215 on such a machine?
As I am only a mathematician and not a logician, I am more
familiar with modulo arithmetics than with logical and'ing;
As long as u is either an unsigned type or a signed type with
a non-negative value.
I think the OP may be confusing external storage and internal,
where endianess typically doesn't matter. In other words,
there may be confusion that registers always hold a literal
copy of ram storage.
...assuming int is at least 25 bits to avoid i<<j from
overflowing.
James said:The size of int is irrelevant here, given that we're shifting an<[email protected]>, James
On Sep 16, 12:16 pm, Ralf Goertz
[...]
But would
unsigned long two_to_the_24th_minus_1()
{
unsigned long i(0);
for (int j=0;j<24;++j)
i|=(1<<j);
return i;
}
return 16777215 on such a machine?
Of course. What else could it return? You're doing
straightforward arithmetic. No bytes are involved, and
certainly no byte order.
...assuming int is at least 25 bits to avoid i<<j from
overflowing.
unsigned long (which is guaranteed to be at least 32 bits).
In the loop, it's shifting the literal 1, which is of type int
(I erroneously referred to that expression as i<<j, when it
was really 1<<j).
<562eed65-f944-4f91-a3de-4b4c709e4...@y38g2000hsy.googlegroups.com>, James
[...]Good point. In the loop, that should be (1UL << j), and not
just (1 << j). And the error will go unobserved unless you
have a machine with ints smaller that 24 bits (which used to
be quite common).
On this tangent, these days it's difficult to write programs
which work with 16-bit ints, since there's little to test on.
One can easily unintentionally rely on more than 16 bits in
int in many unexpected places that are hard to search for. And
using long, or something verbose like int_least_32_t,
everywhere hurts readability. In most of my own code meant to
run on decently powerful machines, I now just put a
preprocessor check that INT_MAX >= 0x7FFFFFFF and use int
almost everywhere.
BTW, add a space after the "--" before your signature and
newsreaders will automatically remove it from the quoted text
when replying.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.