Chap 2 representing and manipulating information (Cs:app)

Source: Internet
Author: User

--------------------------------------------------------------------------------------------------

Author:yumanzi

2014/06/23 1.1-3.5

2014/06/24 3.6-3.8

2014/06/27 on 4.1

2014/06/28 4.2-4.5

--------------------------------------------------------------------------------------------------

1. Information Storage

1.1 Virtual Memory: A machine-level program views Memory as a very large array of bytes.

1.2 Data Sizes (bytes)

Bit:char 1; short [int] 2; int 4; long [int] 4; Long long [int] 8; char * (any pointer) 4; Float 4; Double 8;

Bit:char 1, short [int] 2, int 4; long [int]8; long long [int] 8; char * (any pointer)8;float 4; Double 8;

Contents within square brackets [] is optional. The main difference between + bit machines is following, and points:a) different sizes of data type long; b) different sizes of pointers.

1.3 Byte Ordering: Big endian & Little endian. (Takinh 0x01234567 as example.)

Big endian, the most significant byte comes first (lower address), bytes from low address to high address is 01 23 45 67, respectively;

Little endian, the least significant byte comes first (lower address), bytes from low address to high address is 67 45 23 respectively.

1.4 Shift Operations in C

Left shift << k:dropping off the K most significant bits and filling the right end with K zero;

Logical right Shift >>k:dropping off the k least significant bits and filling the lest end with K zero;

Arithmetic right shift >>k:dropping off the k least significant bits and filling the lest end with K the mostsi Gnificant bit.

Arithmetic right shift uses the most significant bit as filling unit, because of the-the-s complement representation of NE gative integers. In some languages (e.g. Java), the number of shifting bits can never is more than bit sizes of data types.


2. Integral Data Types

2.1 Unsigned Encodings (w bits, x=[x_ (w-1), X_ (w-2),..., X_0])

B2U (x) =sigma{i=[0,w-1]} (X_i*2^i)

B2u means Bits to Unsigned

It can represent integers between [0..2^w-1]

2.2 ' s-complement encodings (same setting as 2.1)

B2T (x) =-x_ (w-1) *2^ (w-1) + sigma{i=[0,w-2]} (X_i*2^i)

B2T means Bits to both ' s

It s a signed encoding, can represent integers between [ -2^ (W-1), 2^ (w-1)-1], the difference between it and Unsigned Encod Dings is the weight of the significant bit, i.e. positive for unsigned and negative for both ' s-complement.

2.3 Conversions

Signed<-->unsigned with identical size:the key was to keep bit representation stable;

Large size-> Small size with same type of signed or unsigned:truncate directly;

<

Chap 2 representing and manipulating information (Cs:app)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.