Hexedecimal Why?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Hexedecimal Why?

Post by computertrick »

This is likely a stupid question but what is the point of hexadecimal because it is a lot easier to read decimal than hexadecimal because you have to preform more calculations to get a decimal value for example

FFFF

15 * 16 + 15 * 16 + 15 * 16 + 15 = 65535

Please no harsh comments I'm just trying to understand because to me 65535 is much easier to read than FFFF
1100110100010011
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Hexedecimal Why?

Post by Combuster »

Because hexadecimal is all about meaning.

FFFF is 16 set bits.

65535 is... a meaningless magic number?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: Hexedecimal Why?

Post by computertrick »

Combuster wrote:Because hexadecimal is all about meaning.

FFFF is 16 set bits.

65535 is... a meaningless magic number?
Lets say I wanted to access another part in memory I would have to calculate another hexadecimal value rather than just add to the decimal number
1100110100010011
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Hexedecimal Why?

Post by iansjack »

Well, if you don't like hexadecimal don't use it. It's not compulsory. It just makes life easier.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Hexedecimal Why?

Post by AJ »

Hi,

Decimal is better for some things, binary for others. Hexadecimal is an extremely useful method of representing bit patterns (and powers of 2) once you get used to it.

Cheers,
Adam
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Hexedecimal Why?

Post by DavidCooper »

I'm a big fan of working with decimals, but for communications with PCI devices, I do all of that in hex. When it comes to decimal addresses, although I use decimals, I keep them divided up in bytes such that I use 255 255 instead of 65535. This means that I'm really working in a mixture of decimals and base 256. 65536 is easy to learn, but would you recognise the significance of 163840 or 49152 at a glance? Unless you have savant-like abilities with numbers, I doubt it.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
gusc
Member
Member
Posts: 50
Joined: Tue Feb 05, 2013 1:42 pm

Re: Hexedecimal Why?

Post by gusc »

Let's put it like this -digital electronics work with numbers that are represented in bits (either 1 or 0). Computer memory can be accessed only in bytes (8 bits, decimal 0-255 or hex 0x00-0xFF). Now the part that makes hex so much readable than dec is that every 2 hex digits always represen a single byte value (8bits) whereas it takes 1-3 decimal digits to do the same.

Here are some examples:
Bin 0000-1111 , hex 0x0F, dec 15
Bin 1111-0000 , hex 0xF0, dec 240
Bin 0000-0010 , hex 0x02, dec 2

Now, once you need to look at some memory region it becomes a lot easier to look at the pair of digits than some mass of 1-3 ones.
tom9876543
Member
Member
Posts: 170
Joined: Wed Jul 18, 2007 5:51 am

Re: Hexedecimal Why?

Post by tom9876543 »

If you couldn't work out the advantages of hexadecimal, its highly likely you will never be able to build an Operating System.
linguofreak
Member
Member
Posts: 510
Joined: Wed Mar 09, 2011 3:55 am

Re: Hexedecimal Why?

Post by linguofreak »

As others have said, computers use binary, and a given number of hexadecimal digits always corresponds to the same number of bits (namely, 4 bits per digit), which isn't the case with decimal, and the bit patterns are often more important than the actual numbers (and even when the actual numbers are important, it's often powers of two that are important).

It's easier to figure out how these numbers are related in hex than in decimal:

00000FFF = 4095
FFFFF000 = 4294963200
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: Hexedecimal Why?

Post by BMW »

computertrick wrote:This is likely a stupid question but what is the point of hexadecimal because it is a lot easier to read decimal than hexadecimal because you have to preform more calculations to get a decimal value for example

FFFF

15 * 16 + 15 * 16 + 15 * 16 + 15 = 65535

Please no harsh comments I'm just trying to understand because to me 65535 is much easier to read than FFFF
Decimal is much easier to read than hexadecimal.

That's only because you grew up with decimal. If you use hex enough, it will become easier to read. If you were brought up using only hex numbers, you would think decimal is hard to read.
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

Re: Hexedecimal Why?

Post by Jezze »

As previously mentioned hexadecimal is simple for understanding what bits are set and which are not but I want to add something a bit off-topic.

There is a something called duodecimal which is just base 12. It would actually be a base much simpler to use in everyday life compared to base 10 which we have today. I think there is even some group or organization trying to promote this.

The reason is simple. Base 12 is simple to use for stuff like division because you easily get halfs, thirds, forths and sixths. There are some other good reasons to for working out the clock etc.

This explains it a bit better: http://www.youtube.com/watch?v=U6xJfP7-HCc
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
User avatar
TightCoderEx
Member
Member
Posts: 90
Joined: Sun Jan 13, 2013 6:24 pm
Location: Grande Prairie AB

Re: Hexedecimal Why?

Post by TightCoderEx »

Consider this memory board, populated with 32 2114 static ram chips. Each chip has 4K bits, so the way this card is configured there are 4 banks 8 bits wide, hense 8 IC's for each bank, thus yielding 16K actually 16,384 or 4000H bytes. Our memory diagnostic indicated that @ location 24C1 we wrote FF, but got CF back. This means that both chip # 3 and 4 (left to right) are damaged and location 4C1 (1217). As we have 4 indentical locations in each bank, the 2 tells us the problem ICs are in bank 3 (second row, right set).

This is an over simplification and I don't even know if board is hardwired in that manner, but the example does demonstrate the value of HEX in determining which IC(s) to change. Base 16 would also have played a very significant part in designing decoder and latch configurations to make this card work.

So you can see by simply shifting address right 12 bits, we're left with the bank where the problem is.

What relevance has this today, probably less than none, because it's been a long time since I've seen a card where the ICs can be changed, but in modern programming there is a lot of attention paid to structure and stack alignment on qword boundaries. At a simple glance, is 5976 evenly divisible by 8 or 191262. Yes and No respectively as it's easy to see 1758 bits 2,1,0 are null and 2EB1E are not, which is what is required for an address to be qword aligned.
rdos
Member
Member
Posts: 3306
Joined: Wed Oct 01, 2008 1:55 pm

Re: Hexedecimal Why?

Post by rdos »

Hex is also very useful when laying out fixed linear addresses, that often should be page-aligned. You cannot easily determine / verify if a decimal address aligns to a page or not, while it is easy when using hexadecimal addresses. You cannot even easily determine if a decimal address is qword aligned.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Hexadecimal Why?

Post by DavidCooper »

I've only ever used one hex editor, so it may not be representative of the norm, but HxD only appears to be able to give you the sector number as a decimal value. I find that really annoying as I keep having to reach for a calculator to work out where things are.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
greyOne
Member
Member
Posts: 58
Joined: Sun Feb 03, 2013 10:38 pm
Location: Canada

Re: Hexedecimal Why?

Post by greyOne »

In a nutshell, (and my opinion)
Hex is a convenient way of bundling 4 binary digits into 1.
This is highly relevant since computers understand binary, not base 10.
Nor hex for the matter, but conversion between bases 2 and 16 is much easier than that of 10.

You can use any base really.
You can even use base 7. Although I strongly advise against the idea.

Might be relevant to the fact the root of 16 is 4, whereas the root of 10 is... 3.162277..etc.
Which happens to be the exact number of binary digits that are represented by a single decimal digit.

Sure, Hex is hard to get used to,
But when you're working with bitflags or addresses,
It's truly a beautiful thing.
Post Reply