| www.delorie.com/archives/browse.cgi | search |
| From: | Goh Yong Kwang <s6606555 AT mercury DOT np DOT ac DOT sg> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | How to convert an unsigned short into a 2 char array? |
| Date: | Mon, 12 Oct 1998 09:45:10 +0800 |
| Organization: | Ngee Ann Polytechnic, Singapore |
| Lines: | 18 |
| Message-ID: | <Pine.SOL.3.91.981012094000.8589A-100000@mercury> |
| NNTP-Posting-Host: | mercury.np.ac.sg |
| Mime-Version: | 1.0 |
| NNTP-Posting-User: | s6606555 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
How do I convert an unsigned short (2 bytes) into a 2 char array?
Does the following code does the trick?
-----------------------------------
char array[2];
unsigned short s = 123; // Initialize it to some sample value first.
array |= s; // OR the bits to copy bit pattern into array.
// Maybe some casting needs to be done.
-----------------------------------
----------------------------------
Many regards,
Goh Yong Kwang
96606555
3K
----------------------------------
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |