Tag Archive for byte

Create emtpy file with predefined size

dd if=/dev/zero of=filename bs=1024 count=20

source

Convert Byte Array to String

byte [] dBytes = { 1, 2, 3, 4, 5}
string str;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
str = enc.GetString(dBytes);

source

Convert String to Byte Array

public static byte[] ToByteArray(string str)
{
System.Text.ASCIIEncoding  encoding = new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}

source

Convert a BufferedImage to a Byte Array as JPEG

public static byte[] bufferedImageToByteArray(BufferedImage img) throws ImageFormatException, IOException{
ByteArrayOutputStream os = new ByteArrayOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
encoder.encode(img);
return os.toByteArray();
}

source

common typedefs for binary data management

typedef unsigned char   Uint8;
typedef signed char     Sint8;
typedef unsigned short  Uint16;
typedef signed short    Sint16;
typedef unsigned int    Uint32;
typedef signed int      Sint32;

typedef long long 	Sint64;
typedef unsigned long long Uint64;

//typedef unsigned char byte;

source