• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - Automation
  • ByteSwap
  • 5.0.0

ByteSwap Class

(Automation::ByteSwap)

The ByteSwap operator lets the user re-position bytes from the default input to default output. More...

Header: #include <ByteSwap>
Inherits: CDPOperator<T>
  • List of all members, including inherited members

Public Functions

ByteSwap(const CDPPropertyBase &in)
~ByteSwap()

Reimplemented Public Functions

virtual void Configure(XMLPrimitive *operatorXML) override
virtual void Create(const char *shortName, CDPBaseObject *parent) override
virtual unsigned int Process() override
  • 18 public functions inherited from CDPOperator
  • 17 public functions inherited from CDPOperatorBase
  • 49 public functions inherited from CDPBaseObject
  • 27 public functions inherited from CDP::StudioAPI::CDPNode
  • 22 public functions inherited from CDP::StudioAPI::ICDPNode

Additional Inherited Members

  • 1 public variable inherited from CDPOperatorBase
  • 1 static public member inherited from CDPBaseObject
  • 1 protected function inherited from CDP::StudioAPI::CDPNode
  • 8 protected variables inherited from CDPOperator
  • 5 protected variables inherited from CDPOperatorBase
  • 10 protected variables inherited from CDPBaseObject

Detailed Description

The ByteSwap operator lets the user re-position bytes from the default input to default output.

Depending on the type size, the ByteSwap has up to 8 numbered 'BytePosition' properties. Each 'BytePosition' property can be assigned a value which indicates where that byte should be positioned in the output. The special BytePosition value '-1' means 'Skip processing of this byte'.

The following table describes the byte-positions in an 8-byte (uint64_t, int64_t, double) signal, and how they relate to Least Significant Byte (LSB) and the Most Significant Byte (MSB):

MSBLSB
76543210

Example

To reverse the order of bytes in an 8-byte type, the following 'BytePosition' property values could be set

NameValue
BytePosition07
BytePosition16
BytePosition25
BytePosition34
BytePosition43
BytePosition52
BytePosition61
BytePosition70

...resulting in a value that is re-mapped to the byte positions shown in this table:

MSBLSB
01234567

Arguments

NameDescription
InThe default input value.
OutThe default output value.

For example: Assume an Input='1' CDPSignal<uint64_t> with a ByteSwap<uint64_t>. If configured with the above BytePositions, a Value of 0x0011223344556677 would yield an InternalValue of 0x7766554433221100.

For signals with less bytes, the scheme is the same, but you only have 4 or 2 BytePosition properties to configure.

Note: There are no restrictions on BytePositions, so in theory it would be possible to map all bytes to position 0. Unused byte-positions will get the value '0', and the last BytePosition written would have precedence over the others.

When operator is used inside a signal its default input is automatically tied to signal's InternalValue or previous operator's output. Its default output is automatically tied to next operator's input or to signal's Value. See also CDP Operator Usage In CDP Signals.

Actual Processing Code of the ByteSwap

unsigned int ByteSwap<T>::Process()
{
  const T input = static_cast<T>(m_input);
  T output = 0;
  const unsigned char* inputPtr = reinterpret_cast<const unsigned char*>(&input);
  unsigned char* outputPtr = reinterpret_cast<unsigned char*>(&output);

  for(std::size_t i=0;i<sizeof(T);++i)
    if((int)m_bytePosition[i]!=-1)
      outputPtr[m_bytePosition[i]] = inputPtr[i];

  m_output = output;
  return STATUS_OK;
}

See also Argument.

Member Function Documentation

ByteSwap::ByteSwap(const CDPPropertyBase &in)

Default constructs an instance of ByteSwap.

ByteSwap::~ByteSwap()

Destroys the instance of ByteSwap.

[override virtual] void ByteSwap::Configure(XMLPrimitive *operatorXML)

[override virtual] void ByteSwap::Create(const char *shortName, CDPBaseObject *parent)

[override virtual] unsigned int ByteSwap::Process()

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2025 CDP Technologies. Privacy and cookie policy.

Return to top