# Group Input negative values ?

**URL:** <https://tech-community.robotics.abb.com/t/group-input-negative-values/2682>\
**Category:** RobotStudio\
**Created:** [April 15, 2009, 3:47pm UTC](https://tech-community.robotics.abb.com/t/group-input-negative-values/2682 "2009-04-15T15:47:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lakris](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@lakris](https://tech-community.robotics.abb.com/u/lakris)\
**Post date:** [April 15, 2009, 3:47pm UTC](https://tech-community.robotics.abb.com/t/group-input-negative-values/2682/1 "2009-04-15T15:47:02Z")

</div>

Hello,

As I understand, ‘Group inputs’ are only interpreted as positive integer values.

Does anybody know if there is a conversion function so that I can convert to integer with sign.

I send values from a Siemens PLC via Profibus/Devicenet gateway and have defined them as an 16 bit Group input.

I send them as 16 bit integers with sign [-32768;32767] as twos complement

Do I have to write a conversion function myself or is there a smarter way?

Thank You,  
lakris

---

<div class="post-metadata">

**Author:** ![msalminen](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@msalminen](https://tech-community.robotics.abb.com/u/msalminen)\
**Post date:** [April 16, 2009, 7:41am UTC](https://tech-community.robotics.abb.com/t/group-input-negative-values/2682/2 "2009-04-16T07:41:57Z")

</div>

I have use following function I made. Remember to select correct notation you need and change it inside my function.

I guess you can also try to change your group input to analog input and use it directly. I think you can search this forum to find thread about it.

FUNC num GetSIntGi(  
VAR signalgi giRead)  
! Function: GetSIntGi 4.9.2006  
! Get signed integer from 16bit (bits 0-15) group input.  
! Bit 15 is the sign bit, so values equal or bigger than 32768 are negatives  
! and needed to be converted to corresponding negative decimal value

VAR num notation;  
VAR num value;  
! There are 2 interpretations for negative binary numbers.  
! Select which notation to use for negative binary numbers.  
! notation:=1 – sign magnitude notation - Returned values are between -32767 to 32767  
! notation:=2 – two’s complement notation - Returned values are between -32768 to 32767  
notation:=2;  
! Get the integer value from group input (from PLC)  
value:=0;  
value:=GInput(giRead);

! Convert unsignad integer to the signed integer according the notation used by PLC  
IF notation=1 THEN  
! Sign magnitude notation  
! bit15 is sign bit, otherwise same as positive binary numbers  
IF value\>32767 THEN  
value:=32768-value;  
ENDIF  
ELSEIF notation=2 THEN  
! Two’s complement notation  
! bit15 is sign bit, negative values are inverted and added 1  
IF value\>32767 THEN  
value:=value-65536;  
ENDIF  
ELSE  
! Notation not set.  
! Return value as it is read.  
ENDIF  
RETURN value;  
ENDFUNC

Regards,  
Mika

---

<div class="post-metadata">

**Author:** ![Thilbi](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@Thilbi](https://tech-community.robotics.abb.com/u/Thilbi)\
**Post date:** [April 16, 2009, 11:18am UTC](https://tech-community.robotics.abb.com/t/group-input-negative-values/2682/3 "2009-04-16T11:18:06Z")

</div>

Hi,

you didnA’t need a function.  
Declare a analog input like this

-Name “aiShiftingX” -SignalType “AI” -Unit “PB\_KARTE” -UnitMap “80-95”  
-MaxPhys 3276.7 -MaxBitVal 32767 -MinPhys -3276.7 -MinBitVal -32767

and you can use the value directly in your program. The range is in this configuration from -3276.7 up to 3276.7.

It is possible to declare an analog input instead a groupinput.

BR  
Thilbi

---

<div class="post-metadata">

**Author:** ![lakris](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@lakris](https://tech-community.robotics.abb.com/u/lakris)\
**Post date:** [May 2, 2009, 11:46am UTC](https://tech-community.robotics.abb.com/t/group-input-negative-values/2682/4 "2009-05-02T11:46:19Z")

</div>

Thank You very much.

I have defined my inputs as analog inputs instead of group inputs, and it works.
