我們的品牌

Impact-Company-Logo-English Black-01-177x54

歡迎造訪施耐德電機全球網站

歡迎訪問我們的網站
		
我们今天能为您提供什么帮助?
TelePACE Studio BCD to Integer

Question:

Is it possible to convert a 4 digit BCD (binary-coded decimal) register into an integer value?

Solution:

A binary coded decimal is where each digit is represented by a fixed number of bits (typically 4). BCD takes advantage of the fact that any one decimal number can be represented by a 4-bit pattern. The most common way of encoding a decimal digit is by its corresponding four-bit binary value.

Simple BCD, also called BCD 8421 encoding is the most common encoding method.

Most BCD values will typically encode 2 digits within a byte (8 bits). This is sometimes called a packed BCD.

Now a 16-bit SCADAPack register in TelePACE can store an unsigned integer between 0-65535. The same 16-bit register can store a BCD value between 0-9999.

The following TelePACE code takes a single register with a BCD value and converts it to an unsigned integer in the SCADAPack. It uses modular math to extract the value for each digit. It then multiplies and adds the pieces back together as an unsigned integer.

Modular math operations to take a BCD value and convert it to an unsigned integer.

A hexadecimal BCD value is input into register 41000 in the decimal range of 0-9999. Let's call it WXYZ. The SCADAPack will interpret the BCD value as an incorrect unsigned integer.

  • Register 41001 MODU 4096 gives the remainder XYZ and puts it in register 43005
  • Register 41001 DIVU 4096 gives the number of thousands W
  • Register 43005 MODU 256 gives the remainder YZ and stores it in register 43003
  • Register 43005 DIVU 256 gives the number of hundreds X
  • Register 43003 MODU 16 gives the remainder Z and stores it in register 43001
  • Register 43003 DIVU 16 gives the number of tens Y

Once the values are determined for W, X, Y and Z, they can be combined together to form an unsigned integer.

This logic recombines the digit values calculated earlier and recreates the value as an unsigned integer  (W*1000) + (X*100) + (Y*10) + Z

  • This logic calculates (W*1000) + (X*100) + (Y*10) + Z and stores the result in register 42001

施耐德電機Taiwan

探索更多
系列:
探索更多
系列:

需要協助?

  • 產品選型工具

    快速輕鬆地為您的應用找到合適的產品和附件。

  • 取得報價

    立即線上提交您的銷售需求,專業團隊將主動聯繫您。

  • 購買地點

    輕鬆在您所在地區找到最近的施耐德電機經銷商。

  • 支援中心

    在同一位置找到滿足您所有需求的支援資源。

  • 產品文檔
  • 軟體下載
  • 產品選型工具
  • 產品替代和替換
  • 幫助和聯絡中心
  • 尋找我們的辦公室
  • 取得報價
  • 人才招募
  • 公司簡介
  • 舉報不當行為
  • 無障礙
  • 新聞中心
  • 投資者
  • 專業洞察
  • 台灣施耐德電機學院
  • 綠色影響力落差調查
  • Schneider Go Green 2025
  • 隱私政策
  • Cookie通告
  • 使用條款
  • Change your cookie settings