This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc. 

Try our online
PLC Simulator FREE.
Click here now to try it.

New Here? Please read this important info!!!
October 15th, 2004, 02:23 PM  #1 
Guest
Posts: n/a

signed and unsigned
Gentlemen,
what exactly is meant/difference between a signed and unsigned integer? I constantly see reference to them but no real explanation. I thank you in advance for your response 
October 15th, 2004, 02:40 PM  #2 
Lifetime Supporting Member + Moderator

Unsigned integers do not allow for values less than zero, signed integers do.

October 15th, 2004, 02:46 PM  #3 
Member

Usually integers use 16 bits. A signed integer uses the highest bit for +/ limiting the range of the integer to what the remaining 15 bits can represent.

October 15th, 2004, 02:49 PM  #4 
Member

With an unsigned integer all of the bits that compose the value have positive values. Therefore you cannot arrive at a negative number.
In a 16bit storage location in a PLC for example this would most commonly mean you could store any number from 0  65535. More typically though the last bit is used to arrive at a negative number. This is usually accomplished using what is called two'scomplement binary. Another less common method is signed magnitude binary. Basically either of those make use of the last bit to indicate a positive or a negative number. So with only 15 bits instead of sixteen, you cannot count as high, only up to 32767. But, you can also count negative down to 32768 (2's complement) or 32767 (signed magnitude). Every PLC I have used, has used 2's complement. Lots of good web sites will explain those two methods if you really wanna go that deep into it. OG 
October 15th, 2004, 03:25 PM  #5 
Guest
Posts: n/a

Thank you all very much!!! That question has been nagging me for some time, and as usual once explained the answer is quite simple! Thanks again guys.....Once again I leave this sight with a little more knowledge than I had when I first came here!

October 15th, 2004, 03:34 PM  #6 
Lifetime Supporting Member

must type faster ... must type faster ...
ok ... I got beat again ... but I'm going to go ahead and post this anyway ...
first let’s look at “signed” integers ... let’s use AllenBradley’s 16bit integers as a specific example ... suppose that we begin with all 16 of the bits equal to “0” ... then the decimal value of the word is “0” ... 0000000000000000 binary equals 0 decimal now turn on the very first (lowest value – the one on the far right – the zero bit  however you want to say it) ... the decimal value of that bit is “1” ... so now the decimal value of the word is “1” ... 0000000000000001 binary equals 1 decimal now leave the first bit on and turn on the next bit too ... the decimal value of that bit is “2” ... so now the decimal value of the word is “3” ... 0000000000000011 binary equals 3 decimal now leave those two bits on and turn on the next bit too ... the decimal value of that bit is “4” ... notice that the decimal value of each bit is double the decimal value of the previous bit ... so now the decimal value of the word is “7” ... yes, there IS a pattern here ... each time we turn on a bit, the value of that bit gets ADDED to the value of all of the other ON bits ... 0000000000000111 binary equals 7 decimal now suppose that we keep turning on each bit rightupto but NOT including the last bit ... (it’s special) ... now the decimal value of the word is 32767 ... 0111111111111111 binary equals 32767 decimal so what about that last bit? ... well first let’s talk about the fact that when you get right down to the basics, the PLC has NOTHING else in its memory except bits ... and each bit can be thought of as a box which can hold either a “1” or a “0” ... NOTHING ELSE ... well that presents a special problem if we ever need to represent a negative number ... think about it this way: if ALL we can put into a bit is either a “1” or a “0”, then how in the heck could we ever enter a negative sign? ... so the PLC designers came up with a clever idea ... let’s use that last bit to represent a negative sign ... now if you were to take the time to keep doubling values the way we were doing earlier, you’d find that the actual value of that last bit is 32768 ... that’s POSITIVE 32768 ... BUT ... since we’ve decided to use this bit as a special “negative sign” bit, then we’ll assign it the value of NEGATIVE 32768 ... that’s right ... we just make up a rule and make it happen ... now ... finally ... turn on that last bit ... as before, we ADD the value of this ON bit (32768) to the value of all of the other ON bits ... 32767 ... do the math and you come up with NEGATIVE 1 ... 1111111111111111 binary equals –1 decimal now just for kicks, turn off all of the bits EXCEPT for the “sign bit” ... since it’s still ON, it ADDS a NEGATIVE 32768 to the value of the integer ... and since all of the other (positive) bits are OFF, then the value of the integer is simply NEGATIVE 32768 ... so that’s the secret handshake for “signed” integers ... a fancy word for this common numbering system is “two’s complement binary” ... now for “unsigned” integers ... again we’ll use all of the preceding rules and start by turning on all of the bits except for the last one ... again 0111111111111111 binary equals 32767 decimal ... so nothing has changed so far ... but this time we won’t use the “special” rule which says that the last bit is to be used as a “negative sign” ... this time we’ll just go ahead and treat this bit like all of the other positive bits ... so its value is now POSITIVE 32768 ... and when we turn that puppy on and ADD its value to all of the other ON bits, we get the total decimal value 65535 ... 1111111111111111 binary equals 65535 decimal but remember ... this is only true for an “unsigned” integer ... and incidentally, AllenBradley always treats their PLC and SLC integers as “signed” integers ... so that’s where their “normal” range of integer values (32767 to –32768) comes from ... (note: the ControlLogix platform has more options) ... I hope this helps ... if you want to play around with these ideas, the best way is to use the RSLogix software and open two windows for an integer file ... set the radix (numbering system) for one of the windows to “binary” ... and set the radix for the other window to “decimal” ... then start changing the bit patterns in one window and watch what happens to the equivalent value in the other ... just remember that with AllenBradley you’re not going to be able to see the “unsigned” integer effect ... one more thing ... the next time you have a SPARE system to play around with, go to the Output Image Table and change its radix to decimal ... find the address of an unused output module ... type in –1 and see what happens to the outputs ...
__________________

October 15th, 2004, 09:13 PM  #7 
Member

thanks to ron for his excellent teaching job!
made it easy to pick up after reading his post! mark 
October 16th, 2004, 02:06 AM  #8 
Member
Join Date: Jul 2004
Location: San Antonio
Posts: 213

i hate to follow up rons great post,,but for more information on 2's compliment,,you can find other awesome information on it with a google search,,and whats even better is when you get into bitwise logic,,what would be nice (and ill work on it ) is to have a posted sticky on bitwise logic and normally used functions,,
lets take XOR(a good one for encryptions),, Code:
101 001 XOR 100 Code:
101 100 OR 101 hope that helps,,and im not too drunk to post bad information,, Fred Raud 
October 16th, 2004, 02:19 AM  #9  
Lifetime Supporting Member + Moderator

Quote:
beerchug Eric 

October 16th, 2004, 02:30 AM  #10 
Member
Join Date: Jul 2004
Location: San Antonio
Posts: 213

thanx for the links mr nelson,,,since its late i didnt do my research and find those links,,and look forward to looking into Rons site,,,this is my first look there,,
and hey,,,dont you have a bedtime Nelson??i thought i was the only one up at this hour,,would be nice to have an mirc channel to chat real time with all the other late night crazies like myself,, Fred Raud 
October 16th, 2004, 03:46 AM  #11  
Lifetime Supporting Member + Moderator

Bedtime? What's that?...
Quote:
Yes, please do have a look around Ron's site, Fred. I think you'd find it interesting... beerchug Eric 

September 11th, 2017, 02:55 AM  #12 
Member
Join Date: Sep 2017
Location: Oradea, Bihor
Posts: 3

USINT data type allen bradley
Hello,
It is possible to change form INT to USINT a variable data type? For the moment, I receive the value 32766 (Local:6:I.Ch0Data) from analogue device (1769IF4XOF2F/A), and I need to be positive. I changed the wiring, but no succes. The settings for input configuration is 0V to 10 V (60 Hz, Raw/Proportional). Someone have any idea? I cannot find to change data type to USINT on allen bradley... Thanks Images: https://imgur.com/a/2bZKf Last edited by Ilasca Marius Cornel; September 11th, 2017 at 02:57 AM. Reason: Change URL image 
September 11th, 2017, 06:04 AM  #13 
Member

@Ilasca Marius Cornel
Please start a new thread, instead of hijacking an old one which is not about troubleshooting input related problems. 
September 12th, 2017, 12:45 AM  #14 
Member
Join Date: Sep 2017
Location: Oradea, Bihor
Posts: 3

@crawler009 Sorry. It was my fault. I have started a new thread. Thanks.

Bookmarks 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)  
Thread Tools  
Display Modes  


Similar Topics  
Thread  Thread Starter  Forum  Replies  Last Post 
Flags, Tags, industry terminology and acronyms.  FORGETFULL MEMBER  LIVE PLC Questions And Answers  7  February 16th, 2005 03:59 PM 
Running display on Panelview  maintpro  LIVE PLC Questions And Answers  13  December 17th, 2003 06:40 AM 
a small ladder for you guys to look at  bob1371  LIVE PLC Questions And Answers  9  July 7th, 2003 11:44 PM 