How things are stored in computer memory?

How things are stored in computer memory?

Computer data storage is a complex subject, but it can be broken down into three basic processes. First, data is converted to simple numbers that are easy for a computer to store. Second, the numbers are recorded by hardware inside the computer. Third, the numbers are organized, moved to temporary storage and manipulated by programs, or software.

Numbers? how?

Every piece of data in a computer is stored as a number. For example, letters are converted to numbers, and photographs are converted to a large set of numbers that indicate the color and brightness of each pixel. The numbers are then converted to binary numbers. Conventional numbers use ten digits, from 0–9, to represent all possible values. Binary numbers use two digits, 0 and 1, to represent all possible values. The numbers 0 through 8 look like this as binary numbers: 0, 1, 10, 11, 100, 101, 110, 111, 1000. Binary numbers are very long, but with binary numbers any value can be stored as a series of items which are true (1) or false (0), such as North/South, Charged/Uncharged, or Light/Dark.

So in memory all looks like this

No alt text provided for this image
No alt text provided for this image


How integers are stored in memory?

Integer data types in C are typically 1, 2, 4 or 8 bytes in length, or 8, 16, 32, or 64 bits in length, but in memory the numbers are storage

But how do we represent signed binary numbers if all we have is a bunch of one’s and zero’s. We know that binary digits, or bits only have two values, either a “1” or a “0” and conveniently for us, a sign also has only two values, being a “+” or a ““.

Then we can use a single bit to identify the sign of a signed binary number as being positive or negative in value. So to represent a positive binary number (+n) and a negative (-n) binary number, we can use them with the addition of a sign.

For signed binary numbers the most significant bit (MSB) is used as the sign bit. If the sign bit is “0”, this means the number is positive in value. If the sign bit is “1”, then the number is negative in value. The remaining bits in the number are used to represent the magnitude of the binary number in the usual unsigned binary number format way.

Example

65

Binary equivalent of 65 is (1000001) 2 .

In our case, 65 is positive so MSB will be 0.

No alt text provided for this image


1’s complement of a number

One’s Complement or 1’s Complement as it is also termed, is another method which we can use to represent negative binary numbers in a signed binary number system. In one’s complement, positive numbers (also known as non-complements) remain unchanged as before with the sign-magnitude numbers.

1’s compliment of number is just inverting binary bits of an actual number.

Example:

10

Binary representation will be (1010) 2

1’s compliment of 10 is, 0101 (switching 0 to 1 and 1 to 0).

2’s complement of a number

Two’s Complement or 2’s Complement as it is also termed, is another method like the previous sign-magnitude and one’s complement form, which we can use to represent negative binary numbers in a signed binary number system. In two’s complement, the positive numbers are exactly the same as before for unsigned binary numbers. A negative number, however, is represented by a binary number, which when added to its corresponding positive equivalent results in zero.

To get 2’s complement of a number, just add 1 to 1’s complement of an actual number.

No alt text provided for this image

This 2’s complement form will be stored in computer.

The main advantage of two’s complement over the previous one’s complement is that there is no double-zero problem plus it is a lot easier to generate the two’s complement of a signed binary number. Therefore, arithmetic operations are relatively easier to perform when the numbers are represented in the two’s complement format.

要查看或添加评论,请登录

Yesid Gonzalez的更多文章

  • Create and publish an NPM package (using NX)

    Create and publish an NPM package (using NX)

    Using "NX" we are going to set up a basic project with a small REACT library that you can deploy to npm. Nx is a smart,…

  • What problems do UX designers solve?

    What problems do UX designers solve?

    User experience is a broad discipline because you must have skills in many different fields or at least know a little…

  • WEB Postmortem

    WEB Postmortem

    A postmortem is a process intended to help you learn from past incidents. It typically involves analysis or discussion…

  • Pow recursion explained

    Pow recursion explained

  • What Happens When You Type in a URL in your browser

    What Happens When You Type in a URL in your browser

    Let's say that you are sitting at your computer, surfing the Web, and you get a call from a friend who says, "check…

  • Do you need the Internet Of Things?

    Do you need the Internet Of Things?

    Maybe you hear about the terms "internet of things" and "artificial intelligence" and you think that is something magic…

  • Basics of Machine Learning

    Basics of Machine Learning

    In these days where the world is interconnected, maybe you hear some terms like Artificial Intelligence Machine…

  • Everything is an object!

    Everything is an object!

    Object-oriented programming refers to a type of computer programming software design in which programmers define not…

  • How object and class attributes work.

    How object and class attributes work.

    What’s a class attribute A class attribute is a Python variable that belongs to a class rather than a particular…

  • Dynamic Libraries C

    Dynamic Libraries C

    Library functions in C language are inbuilt functions which are grouped together and placed in a common place called…

社区洞察

其他会员也浏览了