Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are memory addresses are represented using hexadecimal numbers?

Tags:

Whenever I see C programs that refer directly to a specific location on the memory (e.g. a memory barrier) it is done with hexadecimal numbers, also in windows when you get a segfualt it presents the memory being segfualted with a hexadecimal number.
For example: *(0x12DF)
I am wondering why memory addresses are represented using hexadecimal numbers?
Is there a special reason for that or is it just a convention?

like image 663
the_drow Avatar asked Mar 16 '11 18:03

the_drow


People also ask

Why do we use hexadecimal to represent data?

The main advantage of a Hexadecimal Number is that it is very compact and by using a base of 16 means that the number of digits used to represent a given number is usually less than in binary or decimal. Also, it is quick and easy to convert between hexadecimal numbers and binary.

Are memory addresses in hexadecimal?

Just to make things difficult, memory addresses are normally written not as one but as two hex numbers.


2 Answers

Memory is often manipulated in terms of larger units, such as pages or segments, which tend to have sizes that are powers of 2. So if addresses are expressed in hex, it's much easier to read them as page+offset or similar constructs. Decimal is difficult because of that pesky factor of 5, and binary addresses are too long to be easily readable.

like image 177
Jim Lewis Avatar answered Sep 21 '22 02:09

Jim Lewis


Its a much shorter way to represent what would otherwise be written in binary. It is also very nice and easy to convert hex to binary and back. Each 4 digits of binary corresponds to one digit of hex.

like image 39
BinaryTox1n Avatar answered Sep 20 '22 02:09

BinaryTox1n