• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

What is the purpose of HEX in electronics?

Status
Not open for further replies.

ICNOOB

New Member
Im very noob at this electronics, Iam studying by myself...
please answer it nicely and easily to understood.

Question:

What is the purpose of HEX codes in electronics? why do i need
to program an IC? or is it possible to program it?
 

ericgibbs

Well-Known Member
Most Helpful Member
Im very noob at this electronics, Iam studying by myself...
please answer it nicely and easily to understood.

Question:

What is the purpose of HEX codes in electronics? why do i need
to program an IC? or is it possible to program it?
hi,
HEX is short for Hexadecimal, base of 16. [Decimal is a base of 10]

With 4 bits of data the numbers 0 to 9 A,B,C,D,E,F can be represented.
[the A,B,C,D,E,F have a numeric values of 10,11,12,13,14,15]

The question about programming an 'ic' is too vague.
The program is written to a memory ic [programmed]

The memory can be part of a larger ic eg: a micro controller or it can be a stand alone ic.

Does this help.?:)
 
Last edited:

Noggin

Member
More on the HEX thing...

Lets say you have a microcontroller with an output port on it and you need to set the port to a known value. You would do that by using a line of code such as PORTB = desired output state. Now the desired output state can be a number in decimal (base 10), hex (base 16), octal (base 8), or binary ( base 2 ).

If you know which pins need to be high or need to be low it is very simple to write it in binary. Lets say the outputs need to be the following pattern:

Hi Hi Lo Hi Lo Hi Lo Hi Lo Lo Lo Hi Lo Hi Hi Lo

In binary, that translates to the following

1101010100010110

Very easy, a hi is one and a lo is 0.

To get hex, its just one more step. First you'd think of it as binary, break it into chunks of 4, and then convert it using the values provided by ericgibbs

1101 0101 0001 0110
D516

If you wanted to convert to octal, you'd do something similar but break it into groups of 3 and use the values 0-7

1 101 010 100 010 110
152426

Octal isn't quite as useful though as it is less common than hex, and MCU port sizes are generally multiples of 8.

And finally if you wanted to convert that number to binary you'd get a calculator out.

The result is 54550.

So in the end you could do any of the following:

PORTB = 0b1101010100010110;
PORTB = 0xD516;
PORTB = 0152426;
PORTB = 54550;

To be honest, I'm not sure of what the "standard" way to represent an octal number is in a C compiler. However, I found out (very painfully I should add) that by placing a leading 0 on a decimal number means that it is an octal in Microchips and Hi-Tech's compilers. 0127 is NOT equal to 127. In any case, two of the above options are very clear on what the output states of the microcontroller are, 3 are clear if you are used to thinking in octal (I'd have a hard time not adding a 4th bit probably), and all of them are clear if you're a savant.
 
Last edited:

3v0

Coop Build Coordinator
Forum Supporter
The short answer:
Digital electronics deals with 2 states, on and off. These states are represented with binary numbers. Hexidecimal is a shorthand for binary. It is earier to remeber the hex numbers because they are shorter.

The long answer:
In digital electronics signals are either hi or low. on or off. We choose to represent these as 1 for on/hi or 0 for low/off. A single signal is know as a bit and the number system using only 0's and 1's is binary.

Signals are often grouped together to convey more information or states. 4 bits is a nibble, 8 bits is a byte.

A nibble will have a binary value like 0b1100.
A byte will have binary value like 0b10101111.
Note the 0b tells us the number is in binary and the remainder of the numbers are binary digits or bits.

Binary numbers tend to be long. This makes them hard to work with. We could convert the binary numbers to base 10 but it is difficult to see the relationship between a decimal number and the value of each bit.

Hexidecimal is a better choice. A hex number start with 0x. The 0x is not part of the numbers value. It indicates the hex base.

The binary to hex mappings are:
0b0000 0x0
0b0001 0x1
0b0010 0x2
0b0011 0x3
0b0100 0x4
0b0101 0x5
0b0110 0x6
0b0111 0x7
0b1000 0x8
0b1001 0x9
0b1010 0xA
0b1011 0xB
0b1100 0xC
0b1101 0xD
0b1110 0xE
0b1111 0xF
Anyone who works with digital electronics need to memorize these 16 mappings. Once you have done so you can look at at multi digit hex number and know which bits are on and off.

When one looks at 0x0F one knows the binary value is 0b00001111. The binary value of 0x3C is 0b00111100. You do not need to think or use a culculator to do these conversions, you see the hex and know the binary.

Studens who learn these conversion will work faster and make fewer mistakes. I created a set of flash cards you can print to help learn the conversions between binary, hex, and decimal. Feel free to share them with you teacher and fellow students.

They can be found at: Microchip's University/Academic Corner
Instructions for printing the flash cards.
Hexadecimal to Binary Flashcards
Hexadecimal to Decimal Flashcards

3v0
 

ICNOOB

New Member
Is it the same with programming?? as I read further..
I notice some of Circuits need programming why do I need to do that..
 

Sceadwian

Banned
These are not just simple circuits these are very very complex circuits like micro controllers, or memory. They need data in their program or data areas in order to function at all. Even small micro controllers have more internal components than you will ever use in a single discrete component system in your life.
 

kchriste

New Member
Forum Supporter
I notice some of Circuits need programming why do I need to do that..
Because some chips are actually a complete "computer" on a chip. These are called microcontrollers.
 

solis365

New Member
can you give us a link to what you are reading (if it's online)??... then I could help summarize it or explain it better


i think you are confusing the general term "IC" with other things such as microcontrollers or FPGAs.

IC means an integrated circuit, which basically means that it has its own circuit on the chip. this circuit could be anything, but in your case it sounds like you're talking about a microcontroller, in which the circuit on the IC is actually an entire computer system. (which you do need to "program"). Other IC's could have completely different uses and not need to be programmed, since they are just circuits. if you wanted, you could just put a bunch of resistors on a chip and call it an "IC."

im not really sure how much you know about circuits in general, so heres a couple of links to really basic stuff (if you know it already and are just getting into digital stuff, ignore it, i dont mean to cause offense)
Beginners' Guide to Electronics, Part 1 - Basic Components Explained
Electronics: An Online Guide for Beginners - Home
Tony's Website! Schematics, Circuit Diagrams, Projects, HV, Building, Kits, Tesla, Marconi, 555, R/C, Metal Detecting, Electronics-Tutorials
 

Mikebits

Well-Known Member
I think 3VO said it perfectly. Hex code is a translation language, A way to represent a large amount of symbols into less amount of symbols. It is just a language, no more, no less. It is like saying .000001 farads = 1uf. Which one would you rather write? Scientist and engineers are lazy, shortcuts are common. It is not some grand design or something, it is just as 3VO said, a shortcut.
 

duffy

Well-Known Member
Well if you really DON'T want to program it, you can just use that other meaning of the word "hex" and just cast a magical incantation on it. :)

Seriously, though - you don't program in hex, you use op codes or C. Op codes are like "mov" (move), "and", "or", "decfsz" (decrement file register and skip next instruction if result of decrement is zero).

Not as difficult as you might think.
 

Sceadwian

Banned
Mike, I think 'translation language' is about as bad a description for hex as you can get. (no offense) It's a numbering system. It's just like counting from 1 to 10 only there are more digits than we're used to. Some early computers were 4 bit computers so hex code lent itself readily to viewing the code as each 'digit' represents 4 bits (otherwise known as a nibble) When 8 bit computers came along they simple used two letters spaced a little distance apart to represent all the possible byte values. These two paired digits are also commonly called a 'byte word' Modern computers of a 'word' length of up to 64 bits on the latest Intel and AMD chips.
 
Last edited:

solis365

New Member
Mike, I think 'translation language' is about as bad a description for hex as you can get. (no offense) It's a numbering system. It's just like counting from 1 to 10 only there are more digits than we're used to. Some early computers were 4 bit computers so hex code lent itself readily to viewing the code as each 'digit' represents 4 bits (otherwise known as a nibble) When 8 bit computers came along they simple used two letters spaced a little distance apart to represent all the possible byte values. These two paired digits are also commonly called a 'byte word' Modern computers of a 'word' length of up to 64 bits on the latest Intel and AMD chips.

thats true, it is a numbering system at heart, which should be kept in mind when considering it. but it was invented as a way for humans to more easily work with binary values, since remembering huge strings of 0s and 1s is tough, remembering a few numbers/letters is much easier.

as far as what hex code actually is, i agree with you. but its purpose in electronics is to help us count like computers.
 

3v0

Coop Build Coordinator
Forum Supporter
The original post ask the question

What is the purpose of HEX codes in electronics?
Although I did not use the word translation, it is not off the mark. We translate the binary to hex because humans are better able to deal with the base 16 then base 2.

Yup, hexadecimal is a number system, but the OP did not ask "What is hex".
 

Sceadwian

Banned
Personally I have no problem with binary I find it significantly easier to deal with than hexidecimal actually. It's just used cause it's more compact than listing code in binary which would take up huge amounts of screen/paper space and decimal would need 3 digits for a binary byte simple sollution add a couple letters to the digits and call it a day. Anyone can convert binary to decimal on paper easily, starting from LSB to MSB the value of each place is 1 2 4 8 16 etc... I mean that's it.. nothing to it.. I'd have to search around on the net for a bit but I'm going to guess someone has come up with some paper methods for converting dec-hex and vs versa but not as easily as binary. Hex to binary is a bit annoying with having to memorize the bit tables.
 
Last edited:

tresca

Member
There is only one reason why HEX numbers exist. To make it easier on the programmer. Thats it.

Instead of writing down 10101010, you could write 0xAA. And if you are dealing with alot of values, then coding, and writing them out seems to be a bit of pain, but if we use HEX, we can make an 8 'digit' long 'number' only 2 'digits' since each hex digit is 4 bits.

I dont know if this was said before or not, some of these posts were long and seemed to give alot of examples.

But hex --> simpler for you and me. Thats it.
 

3v0

Coop Build Coordinator
Forum Supporter
If you knew the conversions you would more comfortable working in hex. One has to look at B and know it is 0x1011 without thinking. Anyone who is not there does not know them. He knows of them.

You can function without that ability but the programmer who does, will work faster and quite possibly make less mistakes.
 

Sceadwian

Banned
It is more compact not simpler, there is a difference.
 

duffy

Well-Known Member
Personally I have no problem with binary I find it significantly easier to deal with than hexidecimal actually.
Same here. When you are setting up control registers you usually have something like bit 4 is the UART mode select or bit 3 is address detect enable or something - much easier to deal with in binary than hex.

And when you are loading a timer value or baud rate divisor or something, decimal is easier to deal with than hex.

Hex codes are highly overrated, like Bob Dylan.
 
Last edited:

Sceadwian

Banned
They are compact and break things down nicely for print or display though.
 

3v0

Coop Build Coordinator
Forum Supporter
It is all about using the right base for the right purpose.

In line with what I was saying earlier, if you can't do single digit hex conversion without thinking you do not know them well enough.

I am sure there are a lot of people who program without but it is a handicap. Sort of like having to look up sums in an addition table when doing math.

It is easy for computer math to become an orphan. Some grade schools do not even teach the concept of number bases.

Ther are university courses that teach binary, hex, and the related math. It is a good bet that they are cover rapidly and that the students seldom come up to speed. EDIT: (I would love to be wrong).

3v0
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top