diff --git a/core/Octetstring.cc b/core/Octetstring.cc
index 7eb1e9831406b347a6dd7b09d512baa9f35c1a53..23b206ceaf1c59f500bc4c844bfaa86b8d813ce7 100644
--- a/core/Octetstring.cc
+++ b/core/Octetstring.cc
@@ -1235,8 +1235,8 @@ int OCTETSTRING::RAW_encode(const TTCN_Typedescriptor_t& p_td,
     for (int a = 0; a < blength; a++) bc[a] = val_ptr->octets_ptr[a] << 1;
   }
   else myleaf.body.leaf.data_ptr = val_ptr->octets_ptr;
-  if (p_td.raw->endianness == ORDER_MSB) myleaf.align = -align_length;
-  else myleaf.align = align_length;
+  if (p_td.raw->endianness == ORDER_MSB) myleaf.align = align_length;
+  else myleaf.align = -align_length;
   return myleaf.length = bl + align_length;
 }
 
diff --git a/function_test/RAW_EncDec/RAW_EncDec_TD.fast_script b/function_test/RAW_EncDec/RAW_EncDec_TD.fast_script
index 645c7d6b2962c1e16c24a13dc52ec55a05da0c11..139ff6b6193c29e0798311159ad623214ed57fc2 100644
--- a/function_test/RAW_EncDec/RAW_EncDec_TD.fast_script
+++ b/function_test/RAW_EncDec/RAW_EncDec_TD.fast_script
@@ -375,9 +375,9 @@ testcase TC_FIELDLENGTH_4_and_BYTEORDER_first_for_octetstring() runs on TempComp
 
 testcase TC_FIELDLENGTH_4_for_octetstring_3_octets_long() runs on TempComp {
   const RAW_PDU_18 	i := '123456'O
-  const octetstring 	o := '12345600'O
+  const octetstring 	o := '00123456'O
 
-  if ((enc_RAW_PDU_18(i) == o)and(dec_RAW_PDU_18(o) == i & '00'O)) {setverdict(pass);}
+  if ((enc_RAW_PDU_18(i) == o)and(dec_RAW_PDU_18(o) == '00'O & i)) {setverdict(pass);}
   else {setverdict(fail,"enc_RAW_PDU_18(i)= ", enc_RAW_PDU_18(i), "; dec_RAW_PDU_18(o)= ", dec_RAW_PDU_18(o));}
 }
 
@@ -392,9 +392,9 @@ external function dec_RAW_PDU_19(in octetstring stream) return RAW_PDU_19 with {
 
 testcase TC_FIELDLENGTH_5_for_octetstring_2_octets_long() runs on TempComp {
   const RAW_PDU_19 	i := '1234'O
-  const octetstring 	o := '1234000000'O
+  const octetstring 	o := '0000001234'O
 
-  if ((enc_RAW_PDU_19(i) == o)and(dec_RAW_PDU_19(o) == i& '000000'O )) {setverdict(pass);}
+  if ((enc_RAW_PDU_19(i) == o)and(dec_RAW_PDU_19(o) == '000000'O & i)) {setverdict(pass);}
   else {setverdict(fail,"enc_RAW_PDU_19(i)= ", enc_RAW_PDU_19(i), "; dec_RAW_PDU_19(o)= ", dec_RAW_PDU_19(o));}
 }
 
@@ -418,9 +418,9 @@ testcase TC_FIELDLENGTH_4_and_BYTEORDER_last_for_octetstring() runs on TempComp
 
 testcase TC_FIELDLENGTH_4_and_BYTEORDER_last_for_octetstring_3_octets_long() runs on TempComp {
   const RAW_PDU_20 	i := '123456'O
-  const octetstring 	o := '00563412'O
+  const octetstring 	o := '56341200'O
 
-  if ((enc_RAW_PDU_20(i) == o)and(dec_RAW_PDU_20(o) == i & '00'O)) {setverdict(pass);}
+  if ((enc_RAW_PDU_20(i) == o)and(dec_RAW_PDU_20(o) == '00'O & i)) {setverdict(pass);}
   else {setverdict(fail,"enc_RAW_PDU_20(i)= ", enc_RAW_PDU_20(i), "; dec_RAW_PDU_20(o)= ", dec_RAW_PDU_20(o));}
 }
 
@@ -2924,9 +2924,9 @@ external function dec_RAW_PDU_132(in octetstring stream) return RAW_PDU_132 with
 
 testcase TC_ALIGN_right_for_octetstring() runs on TempComp{
   const RAW_PDU_132 i := '123456'O
-  const octetstring o := '12345600'O 
+  const octetstring o := '00123456'O 
   
-  if ((enc_RAW_PDU_132(i) == o)and((dec_RAW_PDU_132(o) == i & '00'O))) {setverdict(pass);}
+  if ((enc_RAW_PDU_132(i) == o)and((dec_RAW_PDU_132(o) == '00'O & i))) {setverdict(pass);}
   else {setverdict(fail,"enc_RAW_PDU_132(i)= ", enc_RAW_PDU_132(i), "; dec_RAW_PDU_132(o)= ", dec_RAW_PDU_132(o));}
 }
 
@@ -2942,9 +2942,9 @@ external function dec_RAW_PDU_133(in octetstring stream) return RAW_PDU_133 with
 
 testcase TC_ALIGN_left_for_octetstring() runs on TempComp{
   const RAW_PDU_133 i := '123456'O
-  const octetstring o := '00123456'O 
+  const octetstring o := '12345600'O 
   
-  if ((enc_RAW_PDU_133(i) == o)and((dec_RAW_PDU_133(o) == '00'O & i ))) {setverdict(pass);}
+  if ((enc_RAW_PDU_133(i) == o)and((dec_RAW_PDU_133(o) == i & '00'O))) {setverdict(pass);}
   else {setverdict(fail,"enc_RAW_PDU_133(i)= ", enc_RAW_PDU_133(i), "; dec_RAW_PDU_133(o)= ", dec_RAW_PDU_133(o));}
 }