You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
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.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old October 15th, 2004, 02:23 PM   #1
guest
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
  Reply With Quote
Old October 15th, 2004, 02:40 PM   #2
Steve Bailey
Lifetime Supporting Member + Moderator
United States

Steve Bailey is online now
 
Steve Bailey's Avatar
 
Join Date: Apr 2002
Location: The boondocks of Western Massachusetts USA
Posts: 6,537
Unsigned integers do not allow for values less than zero, signed integers do.
  Reply With Quote
Old October 15th, 2004, 02:46 PM   #3
Derek McFarland
Member
Canada

Derek McFarland is offline
 
Derek McFarland's Avatar
 
Join Date: Apr 2004
Location: Vernon, BC
Posts: 133
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.
  Reply With Quote
Old October 15th, 2004, 02:49 PM   #4
Operaghost
Member
United States

Operaghost is offline
 
Operaghost's Avatar
 
Join Date: Apr 2002
Location: Seattle, WA USA
Posts: 2,559
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 16-bit 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's-complement 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
  Reply With Quote
Old October 15th, 2004, 03:25 PM   #5
GUEST
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!
  Reply With Quote
Old October 15th, 2004, 03:34 PM   #6
Ron Beaufort
Lifetime Supporting Member
United States

Ron Beaufort is offline
 
Ron Beaufort's Avatar
 
Join Date: Jul 2002
Location: Charleston, SC
Posts: 5,436
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 Allen-Bradley’s 16-bit 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 right-up-to 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, Allen-Bradley 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 Allen-Bradley 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 ...
__________________

2-B ?
Best regards, ----+----] [----+------------( )----
Ron | |
PLC Training Boot Camp | 2-B |
+----]/[----+

I once was lost, but now am found, was blind, but now I see.

  Reply With Quote
Old October 15th, 2004, 09:13 PM   #7
bakerboy_99ca
Member
Canada

bakerboy_99ca is offline
 
bakerboy_99ca's Avatar
 
Join Date: Mar 2004
Location: London Ontario
Posts: 58
thanks to ron for his excellent teaching job!

made it easy to pick up after reading his post!

mark
  Reply With Quote
Old October 16th, 2004, 02:06 AM   #8
Fred Raud
Member
United States

Fred Raud is offline
 
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
as opposed to OR
Code:
101 
100 OR
101


hope that helps,,and im not too drunk to post bad information,,

Fred Raud
  Reply With Quote
Old October 16th, 2004, 02:19 AM   #9
Eric Nelson
Lifetime Supporting Member + Moderator
United States

Eric Nelson is offline
 
Eric Nelson's Avatar
 
Join Date: Apr 2002
Location: Randolph, NJ
Posts: 4,346
Quote:
Originally posted by Fred Raud
what would be nice (and ill work on it ) is to have a posted sticky on bitwise logic
Phil's got one HERE that's hasn't come unstuck yet. Feel free to expand on it though. It can always find a home at Ron's site (the other Ron).

beerchug

-Eric
  Reply With Quote
Old October 16th, 2004, 02:30 AM   #10
Fred Raud
Member
United States

Fred Raud is offline
 
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
  Reply With Quote
Old October 16th, 2004, 03:46 AM   #11
Eric Nelson
Lifetime Supporting Member + Moderator
United States

Eric Nelson is offline
 
Eric Nelson's Avatar
 
Join Date: Apr 2002
Location: Randolph, NJ
Posts: 4,346
Red face Bedtime? What's that?...

Quote:
Originally posted by Fred Raud
and hey,,,dont you have a bedtime Nelson??
Yup... When the sun comes up. I work the overnight shift, so these are my regular hours, if you can call 5pm to 5am 'regular'...

Yes, please do have a look around Ron's site, Fred. I think you'd find it interesting...

beerchug

-Eric
  Reply With Quote
Old September 11th, 2017, 02:55 AM   #12
Ilasca Marius Cornel
Member
Romania

Ilasca Marius Cornel is offline
 
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 (1769-IF4XOF2F/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
  Reply With Quote
Old September 11th, 2017, 06:04 AM   #13
crawler009
Member
Switzerland

crawler009 is offline
 
crawler009's Avatar
 
Join Date: Feb 2012
Location: Planet Earth
Posts: 195
@Ilasca Marius Cornel

Please start a new thread, instead of hijacking an old one which is not about troubleshooting input related problems.
  Reply With Quote
Old September 12th, 2017, 12:45 AM   #14
Ilasca Marius Cornel
Member
Romania

Ilasca Marius Cornel is offline
 
Join Date: Sep 2017
Location: Oradea, Bihor
Posts: 3
@crawler009 Sorry. It was my fault. I have started a new thread. Thanks.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 12:25 PM.


.