Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Byte representation of numbers in PL/SQL

maxxorJul 18 2010 — edited Jul 24 2010
Hi,

I am developing an SMPP (Short Message Peer to Peer) client in PL/SQL (10g) and I do not know how to convert numbers in the format asked by the Protocol Specification (v3.4).
(If anyone is enterested, the specification document can be found here: Here )

According to the specification, numbers should be represented as "An unsigned value with the defined number of octets (in our case, 4 octets). The octets will always be transmitted MSB first (Big Endian)".

So far, I have found two code examples on the Internet demonstrating this, one in PHP and another in Java.

In the PHP example, the integer numbers are transformed by the "pack" function into unsigned long (always 32 bit, big endian byte order) and then the result is written to the socket. The code where this is done is the following:

$header = pack("NNNN", $v1, $v2, $v3, $v4);
fwrite($this->_socket, $header, 16);

In the java example, the numbers are tranformed into byte arrays using the following code:

int OCTET_MASK = 0xff;
int i = (int) data;
byte[] intBuf = new byte[4];
intBuf[3] = (byte) (i & OCTET_MASK);
intBuf[2] = (byte) ((i >>> 8) & OCTET_MASK);
intBuf[1] = (byte) ((i >>> 16) & OCTET_MASK);
intBuf[0] = (byte) ((i >>> 24) & OCTET_MASK);

They are then concatenated into one byte[] array and then again written to the socket.

Is there a way to achieve this functionality using PL/SQL?

Thank you in advance,

Max
This post has been answered by 706888 on Jul 18 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 21 2010
Added on Jul 18 2010
3 comments
1,433 views