All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ilex.util.PseudoBinary Maven / Gradle / Ivy

Go to download

A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.

The newest version!
package ilex.util;

import ilex.var.Variable;
import decodes.decoder.FieldParseException;

public class PseudoBinary
{
	/**
	 * Convert double to 3-char pseudobinary. 
	 * @param v value to encode
	 * @param rightDigits number of decimal points to encode
	 * @return 3-char pb string
	 */
	public static String encodePB(double v, int rightDigits)
	{
		for(int i=0; i>12) & 0x3f) + 64;
		if (c1 == 127) c1 = 63;
		int c2 = ((iv>> 6) & 0x3f) + 64;
		if (c2 == 127) c2 = 63;
		int c3 = (iv & 0x3f) + 64;
		if (c3 == 127) c3 = 63;
		sb.append((char)c1);
		sb.append((char)c2);
		sb.append((char)c3);
		String ret = sb.toString();
		return ret;
	}

	/**
	 * Convert pseudobinary string to integer.
	 * There are two flavors: signed (range -2^17 ... (2^17)-1)
	 * and unsigned (range 0 ... (2^18)-1)
	 * @param pb the string
	 * @param signed true if the value can be negative.
	 * @return resulting integer.
	 */
//	public static int decodePB(String pb, boolean signed)
//	{
//		int len = pb.length();
//		if (len > 3) len = 3;
//		int v = 0;
//		for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy