How To convert decimal to hexadecimal

squevillon

Member
Join Date
Apr 2008
Location
quebec
Posts
2
Please help, i'm working on a project where i need to convert decimal to hexadecimal, but i dont have a clue on how to do it.


Thanks guys
 
icon4.gif
How To convert decimal to hexadecimal
Please help, i'm working on a project where i need to convert decimal to hexadecimal, but i dont have a clue on how to do it.


Thanks guys


OK here's more details: I'm using rslogix 500 with a micrologix 1100 plc. I need to convert in a string, because i'll have to send the hexadecimal answer to a printer connected to the plc.
 
Please provide an example:

1. Where would the decimal value be?
2. Give an example value for the decimal value.
3. Give an example of th resultant string you want.
 
Assuming your decimal number is stored in a register of some sort, not as a string, then proceed as follows:

Look at the bottom 4 bits of the register
Convert as follows:
0000 -> 0
0001 -> 1
0010 -> 2
0011 -> 3
0100 -> 4
0101 -> 5
0110 -> 6
0111 -> 7
1000 -> 8
1001 -> 9
1010 -> A
1011 -> B
1100 -> C
1101 -> D
1110 -> E
1111 -> F
Shift the register 4 bits Right and then repeat the above (the number of times will depend on the width of the register 8, 16, 32, 64 bits)
 
My bad.... I need to cut back on the caffeine :oops:

EDIT: thank GOD no one ever listens to me, or I might really screw things up :D
 
Last edited:
This would be a piece of cake with a look up table and indirect addressing, except that Rockwell in their misguided belief that a micro PLC should be a stupider PLC made the ML so that it doesn't support indirect addressing in strings. So something that is simple in the ancient technology SLC has to be done by brute force in the ML thereby giving Rockwell customers a happy pain in the butt. [/rant]

Anyways, attached shows how to do it in a SLC with indirect addressing, and just for giggles I threw in a modified version that uses another subroutine and brute force - the subroutine has to be called 4 times.
 
hi,
I tried your example and while it works, it returned 1FF for 255. Am I doing something wrong? Otherwise, you are a really smart guy because if it is a mistake I am sure you will fix it. I am working with an applied motion drive and after the hex conversion, I have to exchange the 4 hex numbers so AABB becomes BBAA. could you help me with that?

Robert Cohen
chicago automation repair service
 
First, do you NEED to convert? If you are dealing with integers, there should be no need to convert. Only if you are sending ASCII to the motion control for example, which seems wasteful.
 
This would be a piece of cake with a look up table and indirect addressing, except that Rockwell in their misguided belief that a micro PLC should be a stupider PLC made the ML so that it doesn't support indirect addressing in strings....

Maybe the clunky (or is that klunky?) way of doing it would be to write xx lines, each line checking if the value EQU 12, if true then write the string "C" to the string to read. Then repeat for every possible value - if you're only dealing with 0 to F then 16 lines, more & the headache grows.
 
Go to your Windows Calculator. Click View... and then Programmer

There are four radio buttons. Hex, Dec, Oct, and Bin

Hex will display your value in Hexidecimal, Dec in Decimal (normal), Oct in Octal (the old PLC-5s used to address in Octal where it would count 0-7 and then 10-17 for the word), and Bin for Binary. Click Dec, type in your value, and switch to Hex to see what it is.
 
This is the problem with resurrecting dead threads. People read this first 2-3 posts and try to answer. Never noticing that the original question was asked in 2008.
 

Similar Topics

I really need your help here! I have a Decimal Number that is being transferred in 1-byte words. The original number is larger than 1 byte...
Replies
2
Views
2,370
Hi all! looking for help converting an 8 bit word SINT tag into decimal. I have an IFM SBN246 flow sensor wired in my controller (L310ER) and it...
Replies
4
Views
2,163
Hey All, i have been fortunate enough to play around with an Applied Motion Products Servo Drive SV200 with 100 watt/ 24vdc congif. I managed...
Replies
2
Views
1,872
Anyone have a good way to convert a decimal number to fractions. Need to convert decimal inches to fractions before sending to HMI
Replies
16
Views
6,489
Hey all, Here's a tricky decimal to binary conversion project I could use some help with: In my RSLogix 5000 application, I have a "checklist"...
Replies
7
Views
3,050
Back
Top Bottom