Lecture Introduction to Computer Programming - Lecture 30

The contents of this chapter include all of the following: Can conditionally compile code, can control line numbers and file names reported by compiler, can emit warnings and errors, can define logical regions of source code. | CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 30 Thanks for Lecture Slides: C How to Program by Paul Deital & Harvey Deital 6Ed. 1 Revisit Data Representations in C 2 Integer Numbers Integers Internal representations of integers is a simple function of powers of 2. Since the computer only understands a 1 or 0, all values must be converted to base 2 in order to be stored in a computer. For Example, the number 107 stored in binary would look like: The value is calculated by selecting, or not selecting values associated with a power of 2. So, 107 is represented as: 107 = 64 + 32 + 8 + 2 + 1 When storing integers, larger numbers are possible by simply using more bits (2 or 4 byte integers). 27 26 25 24 23 22 21 20 0 1 1 0 1 0 1 1 128 64 32 16 8 4 2 1 3 Real Numbers Real Numbers in the decimal system A real number can be expressed as , for example. Some scientific calculators would use the format * 10 2. Computers typically use something closer to the second form So the Real numbers float or double are more complicated to represent than integers because we need to deal with 4 distinct components. . 4 In Decimal, we would say that * 10 2 consists of the following components: the sign ( - ) the Radix is 10 (base 10) the Exponent is 2 the Mantissa is When representing real numbers, the component parts are: Sign bit indicating whether number is positive or negative. The base or radix for exponentiation which is almost always 2 The exponent to which the base is raised (sometimes this is offset by a fixed number called a bias) The mantissa or significant, an unsigned integer representing the number Real Numbers and their components 5 Float and Double A float in C++ is typically: composed of 32 bits (4 bytes) comprised of: A sign bit. 8 bit exponent (bias of 127) 23 bit mantissa A double in C++ is typically: composed of 64 . | CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 30 Thanks for Lecture Slides: C How to Program by Paul Deital & Harvey Deital 6Ed. 1 Revisit Data Representations in C 2 Integer Numbers Integers Internal representations of integers is a simple function of powers of 2. Since the computer only understands a 1 or 0, all values must be converted to base 2 in order to be stored in a computer. For Example, the number 107 stored in binary would look like: The value is calculated by selecting, or not selecting values associated with a power of 2. So, 107 is represented as: 107 = 64 + 32 + 8 + 2 + 1 When storing integers, larger numbers are possible by simply using more bits (2 or 4 byte integers). 27 26 25 24 23 22 21 20 0 1 1 0 1 0 1 1 128 64 32 16 8 4 2 1 3 Real Numbers Real Numbers in the decimal system A real number can be expressed as , for example. Some scientific .

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.