Baosong Wu
Architect@SR-Intellience
# PRESENTING CODE
# PRESENTING CODE
# PRESENTING CODE
1 1 0 1 = 13
0 1 1 0 = 6
# PRESENTING CODE
| Type | Minimum Magnitudes | x86-32 |
|---|---|---|
| unsigned char | 255 (2^8 - 1) | 255 (2^8 - 1) |
| unsigned short | 65536 (2^16 - 1) | 65536 (2^16 - 1) |
| unsigned int | 65536 (2^16 - 1) | 2^32 - 1 |
| unsigned long | 2^32 - 1 | 2^32 - 1 |
| unsigned long long | 2^64 - 1 | 2^64 - 1 |
# PRESENTING CODE
0000101011 = 43
1000101011 = -43
Sign and Magnitude
Ideation
During the ideation phase, expect to discuss the project in depth to clearly understand the goals and requirements.
0000101011 = 43
1000101011 = -43
Launch
It's time to take the product live - the end if the build phase but the beginning of being in market.
One's complement
0000101011 = 43
1111010100 = -43
Two's complement
0000101011 = 43
1111010101 = −43
# PRESENTING CODE
| Value | Sign and Magnitude | One's complement | Two's complement |
|---|---|---|---|
| 0 | 0000000000 | 0000000000 | 0000000000 |
| -0 | 1000000000 | 1111111111 | N/A |
| 1 | 0000000001 | 0000000001 | 0000000001 |
| -1 | 1000000001 | 1111111110 | 1111111111 |
| 511 | 0111111111 | 0111111111 | 0111111111 |
| -511 | 1111111111 | 1000000000 | 1000000001 |
| 512 | N/A | N/A | N/A |
| -512 | N/A | N/A | 1000000000 |
# PRESENTING CODE
# PRESENTING CODE
| Type | Minimum Magnitudes | x86-32 |
|---|---|---|
| char | -127 ~ 127 | -128 ~ 127 |
| short | -32767 ~ 32767 | -32768 ~ 32767 |
| int | -32767 ~ 32767 | -2^31 ~ 2^31 - 1 |
| long | -(2^31 - 1) ~ 2^31 - 1 | -2^31 ~ 2^31 - 1 |
| long long | -(2^63 - 1) ~ 2^63 - 1 | -2^63 ~ 2^63 - 1 |
# PRESENTING CODE
# PRESENTING CODE
char cresult, c1, c2, c3;
c1 = 100;
c2 = 3;
c3 = 4;
cresult = c1 * c2 / c3;unsigned char uc = UCHAR_MAX; // 0xFF
int i = ~uc;
cout << hex << i << endl;# PRESENTING CODE
# PRESENTING CODE
# PRESENTING CODE
# PRESENTING CODE
# PRESENTING CODE
# PRESENTING CODE
// overflow
int i;
unsigned int j;
i = numeric_limits<int>::max(); // 2,147,483,647
i++;
cout << "i = " << i << endl;
j = numeric_limits<unsigned int>::max(); // 4,294,967,295;
j++;
cout << "j = " << j << endl;
i = numeric_limits<int>::min(); // -2,147,483,648;
i--;
cout << "i = " << i << endl;
j = 0;
j--;
cout << "j = " << j << endl;# PRESENTING CODE
void getComment(size_t len, char *src)
{
size_t size;
size = len - 2;
char *comment = (char *)malloc(size + 1);
memcpy(comment, src, size);
return;
}# PRESENTING CODE
# PRESENTING CODE
// truncation
char c3, c1, c2;
c1 = 100;
c2 = 90;
c3 = c1 + c2;int main(int argc, char *argv[])
{
unsigned short int total;
total = strlen(argv[1]) + strlen(argv[2]) + 1;
char *buff = (char *)malloc(total);
strcpy(buff, argv[1]);
strcat(buff, argv[2]);
/* ... */
}# PRESENTING CODE
# PRESENTING CODE
# PRESENTING CODE
// sign error
int i = -1;
unsigned int u;
u = i;
cout << "u = " << u << endl;void initialize_array(int size)
{
if (size < MAX_ARRAY_SIZE)
{
array = malloc(size);
/* initialize array */
}
else
{
/* handle error */
}
}# PRESENTING CODE
# PRESENTING CODE
short total = strlen(argv[1])+ 1;# PRESENTING CODE
=>
size_t total = strlen(argv[1])+ 1;vector<char> a;
...
size_t cnt = a.size();
for (unsigned int i = cnt-2; i >= 0; i--) {
a[i] += a[i+1];
}# PRESENTING CODE
=>
for (int i = cnt-2; i >= 0; i--) {
a[i] += a[i+1];
}# PRESENTING CODE
unsigned char waterTemperature;using watertemp_t = unsigned char;class watertemp_t {
};# PRESENTING CODE
# PRESENTING CODE
unsigned int ui1, ui2, usum;
/* Initialize ui1 and ui2 */
if (UINT_MAX - ui1 < ui2) {
/* handle error condition */
}
else {
usum = ui1 + ui2;
}# PRESENTING CODE
unsigned int ui1, ui2, usum;
/* Initialize ui1 and ui2 */
usum = ui1 + ui2;
if (usum < ui1) {
/* handle error condition */
}# PRESENTING CODE
int main(int argc, char *const *argv) {
try{
SafeInt<size_t> s1(strlen(argv[1]));
SafeInt<size_t> s2(strlen(argv[2]));
char *buff = (char *) malloc(s1 + s2 + 1);
strcpy(buff, argv[1]);
strcat(buff, argv[2]);
}
catch(SafeIntException err) {
abort();
}
}# PRESENTING CODE
* Due to the highly nested nature of this class, you can expect relatively poor
* performance in unoptimized code. In tests of optimized code vs. correct inline checks
* in native code, this class has been found to take approximately 8% more CPU time (this varies),
* most of which is due to exception handling.# PRESENTING CODE
Thank you!
# PRESENTING CODE