× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Chaps,
 
I am writing some code to import data from a stream file. The numeric data
is held in little-endian byte order. Is there an easy way to handle/convert
this data to big-endian byte order?
 
I tried a simple conversion as follows:
 
*****************************************************************
p convertEndian   b                                              
*****************************************************************
d convertEndian   pi            10i 0                            
d integerIn                     10i 0 value                      
                                                                 
d                 ds                  static                     
d integerOut                    10i 0                            
d integerOut_1                   3u 0 overlay(integerOut:1)      
d integerOut_2                   3u 0 overlay(integerOut:2)
d integerOut_3                   3u 0 overlay(integerOut:3)
d integerOut_4                   3u 0 overlay(integerOut:4)
*****************************************************************
 /free                                                           
                                                                 
  // Convert byte order...                                       
  integerOut = integerIn;                                        
  return (integerOut_1) + (integerOut_2 * (2**8)) +              
         (integerOut_3 * (2**16)) + (integerOut_4 * (2**24));    
                                                                 
 /end-free                                                       
*****************************************************************
p convertEndian   e                                              
***************************************************************** 
 
I know this isn't totally correct, and I'm not sure if it would handle
negative numbers. Will simply swapping the byte order do the job? I'm not
sure where the sign bit is in both cases. I assume that it will work for
unsigned ints/shorts (obviously replacing the i with a u).
 
OR - is there a way of defining a numeric field (int, short) as
little-endian in RPG???
 
Your help would be appreciated.
 
Cheers
 
Larry Ducie   

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.