{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ch2scalartypes

# ch2scalartypes - Chapter 2 Scalar Types Outline Binary...

This preview shows pages 1–9. Sign up to view the full content.

Chapter 2 Scalar Types Outline: Binary, Octal, Hexadecimal, and Decimal Numbers Character Set Comments Declaration Data Types and Constants Integral Data Types Floating-Point Numbers and Metanumbers Introduction to Pointers Initialization Introduction to Formatted Input and Output

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Binary, Octal, Hexadecimal, and Decimal Binary Binary numbering system has only two possible values for each digit: 0 and 1 . The digits' weight increases by powers of 2. The weighted values for each position is determined as follows: 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 1 2 8 6 4 3 2 1 68421 For example, the binary value 1100 1010 represents the decimal value 202. 1 * 128 + 1 * 64 + 0 * 32 + 0 * 16 + 1 * 8 + 0 * 4 + 1 * 2 + 0 * 1 = 128 + 64 + 0 + 0 + 8 + 0 + 2 + 0 = 202 (decimal)
Binary Two’s Complement The left-most bit is the sign bit. If it is 1, then the number is negative. Otherwise, it is positive. Give a negative value, represent it in binary two’s complement form as follows. 1. write the number in its absolute value. 2. complement the binary number. 3. plus 1. Example, represent –2 in binary two’s complement with 16 bits for short int . Binary value of 2: 0b0000 0000 0000 0010 Binary complement of 2: 0b1111 1111 1111 1101 Plus 1: +1 Binary two’s complement representation of -2: 0b1111 1111 1111 1110

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Give binary two’s complement form of a negative number, find the absolute value of the negative value as follows. 1. Complement the binary number. 2. Plus 1. Example, find the decimal value of (0b1111 1111 1111 1110) 2 in binary two’s complement form with 16 bits. Binary two’s complement (0b1111 1111 1111 1110) 2 Binary complement (0b0000 0000 0000 0001) 2 Plus 1 +1 Absolute value: (0b0000 0000 0000 0010) 2 = 2 10 Negative value: -2
Subtraction of a value in the computer can be treated as addition of its two’s complement. For example, the subtraction of (2-2) can be performed as 2+(-2) as follows: 0b0000 0000 0000 0010 (binary representation of 2) 0b1111 1111 11111110 (two’s complement representation of -2) 0b0000 0000 0000 0000 (2+(-2))

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example > short i, j > i = 0b0000000000000010 2 > j = 0b1111111111111110 -2 > i+j 0
Octal The octal system is based on the binary system with a 3-bit boundary. The octal number system uses base 8 includes 0 through 7. The weighted values for each position is as follows: 8 3 8 2 8 1 8 0 512 64 8 1 1. Binary to Octal Conversion Break the binary number into 3-bit sections from the least significant bit (LSB) to the most significant bit (MSB). Convert the 3-bit binary number to its octal equivalent. For example, the binary value 1 010 000 111 101 110 100 011 equals to octal value (12075643) 8 .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2. Octal to Binary Conversion Convert the octal number to its 3-bit binary equivalent. Combine all the 3-bit sections. For example, the octal value 45761023 equals to binary value 100 101 111 110 001 000 010 011. 3. Octal to Decimal Conversion To convert octal number to decimal number, multiply the value in each position by its octal weight and add each value together. For example, the octal value (167) 8 represents decimal value 119.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 47

ch2scalartypes - Chapter 2 Scalar Types Outline Binary...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online