Skip to content

Bite char : Byte char

February 8, 2011
tags:

Byte is 8 bit signed 2 s compliment that can have max of 127 and min of -128 vals.
Char is 16 bit unsigned unicode character.
1 char can only come in 1 byte if the encoding is ASCII or ISO-8859-1
otherwise – 1 char can take more than 1 byte – so it’s dependent on the charset encoding.

To convert char to a byte :
a. (byte) ‘a’ if simple ascii
b. String(new char[]{‘a’}) .getBytes(“utf-8”)
c. Push data into ObjectOutputStream(ByteArrayOS) and call oOS.writeObject(obj) and barrayos.toByteArray() gives you the array of bytes of data.
d.

Arrays.copyOfRange

int ,float: 32
long, doubt: 64
short : 16 signed
byte : 8 signed
char: 16 unsigned

Questions
———————-
1/ What is shift bit?
java.nio.ByteOrder.nativeOrder();
ret[0] = (byte)(x & 0xff);
ret[1] = (byte)((x >> 8) & 0xff);

2/ shift to int conversion?

3/ shift to byte array conversion – 0 to 65365?

4/ float arithemitic ?

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: