Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading bits in a memory

Tags:

c++

If I have a pointer to the start of a memory region, and I need to read the value packed in bits 30, 31, and 32 of that region, how can I read that value?

like image 375
Blade3 Avatar asked Aug 11 '10 18:08

Blade3


People also ask

How many bits are in a memory?

Memory locations are 8-bits, but pointers are 32 bits (or 64 or whatever), not 8.

How is a byte read from memory?

@Progear: When the process is reading a byte, it will read the 32-bit word the byte is in. Those 32 bits go from the bus into a shift unit that is in line with the load unit. The desired 8 bits come out of the shift unit and go into the general processor register (or equivalent) that they are being loaded into.

How are bits represented in memory?

A piece of computer memory can be represented by a series of 0's and 1's, with one digit for each bit of memory; the value 1 represents an “on” bit and a 0 represents an “off” bit. This notation is described as binary form.


1 Answers

Use bit masks.

like image 127
Klaim Avatar answered Sep 22 '22 09:09

Klaim