$signed="-281581062704388899"; $bits = unpack("B*", pack("N", $signed)); $base64 = encode_base64(pack("B*", $bits), ""); #or $base64 = encode_base64($bits);