desmondoray / csapp-3e Goto Github PK
View Code? Open in Web Editor NEWSolutions of Computer Systems: A Programmer's Perspective ,Third Edition
Solutions of Computer Systems: A Programmer's Perspective ,Third Edition
Line 4 is wrong.
It should be
B (c)
n should be 19/63
long switch_prob(long x, long n) { long result = x; switch (n) { case 60: case 62: result = 8 * x; break; case 63: result = x >> 3; break; case 64: result = 15 * x; x = result; case 65: x *= x; default: result = x + 75; break; } return result; }
This code does not work properly when x contains most significant bit set to 1, e.g. 0xFFFFFFFF
.
Maybe this solution might avoid this problem:
0x1
to set bit(x == 0)
to return 0 in this case: unsigned add_bit = (x == 0);
x >>= 1;
return (x + add_bit);
So the code will look like this:
int leftmost_one(unsigned x)
{
unsigned add_bit = (x != 0);
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
x >>= 1;
return (x + add_bit); // Add 1 if x != 0, 0 otherwise
}
Thanks!
/**
P 3-61
long cread(long *xp) {
return (xp ? *xp : 0);
}
Explain:
The key point is to avoid * and xp come together.
*/
long cread_alt(long xp) {
long a=0;
return *(xp? xp:a);
}
failed for test case: lower_one_mask(32) == 0xFFFFFFFF
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.