'Hexadecimal Convention in address [duplicate]

How the 4kb is 0FFF in Hexadecimal

Can anyone explain how it is 0FFF so how to solve this type of questions in general



Solution 1:[1]

How does hex notation work?

You count in base 10

496
^^^
|||
|||___ the 'ones' column        6 * 1 +
||____ the 'tens' column        9 * 10 +  
|_____ the 'hundreds' column    4 * 100
                               =496

In base n counting there are n different symbols used -> 0,1,2,3,4,5,6,7,8,9 for base 10

Computers work in binary - which is base 2, so 2 symbols used 0 and 1

decimal 14 written in binary is

1110
||||___the 'ones' column      0 * 1 +
|||____the 'twos' column      1 * 2 +
||_____the 'fours' column     1 * 4 +
|______the 'eights' column    1 * 8
                             =   14 (decimal)

496 in binary is

000111110000

Thats kind of hard to read , but we can do a trick

We can change to base 8 tho (digits 0-7)

Now we can write it as

 760

We note something interesting, if we group that binary into sets of three

 000 111 110 000

and look at each group we see that its

 0   7   6   0      

if we interpret each triple of three binary digits.

This is called 'octal' and was used by a lot of early computers that had natural 'word' sizes of 6 or 9 bits

Nowadays we have machines that use 16,32,64 bit words. So now we changed to base 16 (groups of four)

Base 16 needs 16 digits, 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f (somebody had to choose those, they could just as easily chosen q,w,e,r,t,y or !@#$%^, just needed single character symbols for the digits after 9)

Now look at 496 again

000111110000

group in fours

0001 1111 0000
   1    F    0

so 496 decimal is 1F0 in hex

Looked at another way

  1F0
  |||____ ones column      0 * 1 +
  ||_____ sixteens    F(15) * 16
  |______ 256s column      1 * 256
                          = 496

So lets look at 0x0fff. This is one less than 0x1000 - thats easier

 0x1000
   ||||__ 0s col
   |||____16s col
   |______256s col
   |______4096s col

remeber each col is worth 'base' times the previous column

so 0x1000 is 4096

Most people will say 4k rather the four thousand and ninety six. Its no exact but we know what they mean. Likewise

 0x800 is 2k (really (2048)
 0x400 is 1k (really 1024)
 0x10000 is 64k (really 65536)
 0x100000 is 'one meg', really(1048576)

these are all neat powers of 2, important because they match things like register sizes. A 16 bit registers can hold a max value of

0xffff = 65535 

so people say tha for example a sixteen bit register can address 64k of memory (actually 655536 different addtreeses 0 - 655535)

Your

 0xfff (one less than 0x1000)

is how many bits can be stored in a 12 bit register

 0xfff = 4095 or 4096 different addresses of values (0 to 4095)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Cordes