If digital data is stored in 0s & 1s, how does the reader know how many of the digits to take into consideration?

948 views

Must be a very basic and dumb question. But ‘1001’ can be 9 and also 2 & 1 if ’10’ & ’01’ is taken seperately. I’m confused.

In: 49

48 Answers

Anonymous 0 Comments

Bytes are usually organized into words which can be multiple bytes and are the basic unit handled by computers (primary width of the registers used by the CPU usually). The computer itself just performs the requested operation on the word whether that is some arithmetic, logical, store, rotation, shift. The computer does NOT care what the data represents it it just does what it’s told.

Interpretation of the data is left up the the software. I (or my compiler) will frequently stuff multiple items within a single word. I do a lot of microcontroller stuff and we are very limited on the amount of program and data memory available. My code will know that my data is located in bits 4 through 8 of the word–because I wrote the code and designed it that way. To access this data I need to do extra operations like shifting the word 4 bits to the right and then masking (setting to zero) all the bits 4 and greater of the word. This leaves me with the data of bits four through eight.

In the example above I’ve reduced the required data memory by packing the data into just the required bits; however, I’ve slowed down my code–it requires extra operations to access the data. On modern computers, the memory is essentially limitless and you’d never really bother to pack the data. Speed is more important so you’d just put your 4-bits of data in its own word and waste the unused bits. (I’m talking simple program data/variables–if you’re doing movies or something you will likely compress the hell out if it).

You are viewing 1 out of 48 answers, click here to view all answers.