🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16107

Writing a binary short out to a buffer

#16107
From: Robert J. Muller
Date: Wed, 24 Mar 1999 00:00
17 lines
1036 bytes
I'm converting an elderly C program to Java, and one function writes  a
message into a buffer preceded by a header containing two short integers
in the first four bytes of the file (pardon the globals):

char gbuffer[8192];

void write(char *message, short len, short b) {

memcpy(gbuffer, (char*)&len, 2);
memcpy(&gbuffer[2], (char*)&b, 2);
memcpy(&gbuffer[4], message, len+1);
}

Can anyone tell me how to get the first four bytes of a byte[] to look
like this given two shorts?

  --Bob Muller
Technical Details
Message-ID: <36F98F28.98E2C5B2@valuestar.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,d7e6823912d8922a,start
X-Google-Attributes: gidf74b3,public
From: "Robert J. Muller" <bmuller@valuestar.com>
Subject: Writing a binary short out to a buffer
Date: 1999/03/24
Message-ID: <36F98F28.98E2C5B2@valuestar.com>
X-Deja-AN: 458745263
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
Organization: ValueStar, Inc.
Mime-Version: 1.0
Reply-To: muller@computer.org
Newsgroups: borland.public.jbuilder.java.language