diff --git a/src/backend/libpq/pqcomprim.c b/src/backend/libpq/pqcomprim.c
index 7631e1c76500b819450f38aefe83d5df453fb196..17c0a2fba5bc2639bbc125af55f13d7a201d84f3 100644
--- a/src/backend/libpq/pqcomprim.c
+++ b/src/backend/libpq/pqcomprim.c
@@ -34,12 +34,20 @@
 #else
 #if BYTE_ORDER == BIG_ENDIAN
 
+/*
 #define ntoh_s(n)	(uint16)(((u_char *)&n)[1] << 8 \
 			  | ((u_char *)&n)[0])
 #define ntoh_l(n)	(uint32)(((u_char *)&n)[3] << 24 \
 			  | ((u_char *)&n)[2] << 16 \
 			  | ((u_char *)&n)[1] <<  8 \
 			  | ((u_char *)&n)[0])
+*/
+#define ntoh_s(n)	(uint16)((((uint16)n & 0x00ff) <<  8) | \
+				 (((uint16)n & 0xff00) >>  8))
+#define ntoh_l(n)	(uint32)((((uint32)n & 0x000000ff) << 24) | \
+				 (((uint32)n & 0x0000ff00) <<  8) | \
+				 (((uint32)n & 0x00ff0000) >>  8) | \
+				 (((uint32)n & 0xff000000) >> 24))
 #define hton_s(n)	(ntoh_s(n))
 #define hton_l(n)	(ntoh_l(n))