Question I was asked, where are these derived from

russrmartin

Member
Join Date
Aug 2002
Location
Eastman, Wisconsin
Posts
744
I was asked the other day by somebody where the #s +-32767 and +-4095 are derived from. I came to the conclusion that I had no idea really, I had just accepted the fact that they are what they are and used them accordingly. Anyone have any input?

Russ
 
+- 32767 is a 16 bit integer, i.e. if all 16 bits were on you would have a number of 65534 but they often use the last (left hand side bit) to determine + or - hence the +-32765. 4095 is the same deal but in a 12 bit format so it will be between 0 and 4095, I don't think the first bit is often used as a sign bit bit if it was it would be +-2047. Just different ways of showing 1 and 0.
 
The range, in decimal notation, for a 16-bit signed integer is -32768 to +32767 (two's complement format).

A 12-bit binary number (typical analogue input) has a range 0 to 4095.
 
The numbers you mention are defined by the number of bits.
The number is based on the 'Base 2' number system. In memory, you can only have 2 states - on or off. With one bit, you can only count to 1 - Zero or 1. With 2 bits, you can count 0-3. 4 bits, 0-15.
Each time you add a bit, the highest number doubles.
2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536.
Typical numbers in a PLC:
8 bits = 0-255
12 bits = 0-4095 (Analog cards are typically 12 bit)
16 bits = 65535. Usually split in a PLC as -32767 to +32767.
The CPU is 16 bit. Internally, they use 15 bits to count from 0-32767. The 16th bit is called the 'sign' bit.

For darrenj,
4 bits = Nibble
8 bits = Byte
16 bits = Word
32 bits = Double Word
 
No sarcasm intended here , and the advice you've been given is good , but you may also want to take a look at the other common relationships with regard to data types , as all these things are very closely tied up .
 
May PLCs now have 64 bit maths - signed and unsigned. Then there is IEEE 754 floating point and my favourite PLC now has 64 bit floating point - Mantissa etc.

When referring to word types IEC, the following applies
UINT = unsigned integer - 16 bits - 0 to 65535
INT = signed integer - 16 bits - -32767 to + 32767
ULINT = unsigned integer long - 32 bits - 0 to 4294967295
LINT = signed long integer - 32 bits - 0 to 2147483647.
Then on to 64 bit Etc, Etc

The easiest way to see the relationship is to use the Windows calculator. For example, a signed 16 bit word uses 15 bits for the value. Select binary, type in 15 x 1s and change the value representation to decimal. The result is 32767. As you have only typed in 15 x 1s, the most significant bit is the sign - 0 for positive and 1 for negative. This represents the IEC word type INT (signed integer). The Windows calculator is absolutely invaluable for converting word types. For all of us who play with word types in PLCs, the calculator is probably the best accessory available in Windows. And when one is bored beyond belief waiting on others to gate their s**t right, there is Solitare, Minesweeper etc.
 
Last edited:
Why?

Why 4, 8, 16, 32, 64, 128 bits etc?
PDP 8s have 12 bit registeres. I beleive there were some old 36 and 18 bit mini computers in the past. PIC microcontrollers have 12, 14 and 16 bit instructions depending on the model.
Early Intel micro controllers had 4 bit registers. Look up the 4004 and 4040. Actually 4 bit microcontrollers are still used today. There are Motorola/Freescale DSPs that use 24 bit registers and Analog Devices has DSPs with 48 bit instructions and 32 bit data. TI has 128 bit instructions. Actually it fetches 128 bits at a time and there are as many as 8 16 bit instructions in the 128 bits.
Why 4, 8, 16, 32, 64,128 bits etc?

LINT = signed long integer - 32 bits - 0 to 2147483647.
Not quite right. What is wrong?

What is the largest odd integer that can be represented in a 32 bit float?
 
LINT - Error is not giving the lower boundry correctly (-2147483647)

Largest odd integer for a 32 bit IEEE 754 float? Hrm...
It should be a 24 bit mantissa, no? so 16777215?

Hrm.. thinking about it... it is really a 23 bit mantissa, with a phantom 1 assumed for the 24'th bit. So, the max would be actually 0x7fffff, which is 8388607 as the fractional part, stick a 1 in front, you get 18,388,607. Is that right?

trying to remember number formats for floating point always makes my head hurt.
 
Last edited:

Similar Topics

The training class I just finished today was really great. I now have a good understanding of vfds. I cannot wait to take this knowledge into the...
Replies
2
Views
9,460
I have a 120V relay, 120V DI card and a analog input. I was wanting to know if i could put a 24V DI and well as a 120V DI card on the same plc...
Replies
1
Views
63
Hello again..trying something on an existing poorly written program and just wanted to double check something system is an A-B MicroLogix 1200 In...
Replies
5
Views
184
Good morning! Let me start by saying, I am still learning about this type of HMI programming. I recently watched a video about recipes and how it...
Replies
4
Views
166
I have some logic that I have written within a 5380 series controller that tracks the time an event is started, while the event is running an RTO...
Replies
2
Views
102
Back
Top Bottom