JAPI 0.9.0
Yet another Java API
API Documentation

net.sf.japi.io
Class BCD

java.lang.Object
  extended by net.sf.japi.io.BCD

public final class BCD
extends Object

A class with methods for converting BCD data from and to Binary data. Currently only int is supported. Probably net.sf.japi.io is not the ideal package for this class, yet it seems most appropriate.

Author:
Christian Hujer

Method Summary
static int base10(int n)
          Return the 10 base (10^n).
static int bcd2int(int bcd)
          Convert a BCD value to an int value.
static void check(int bcd)
          Check wether a BCD value is correct.
static int correct(int bcd)
          Perform a BCD correction.
static int int2bcd(int val)
          Convert an int value to a BCD value.
static boolean isBcd(int bcd)
          Check wether a BCD value is correct.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

bcd2int

public static int bcd2int(int bcd)
Convert a BCD value to an int value.

Parameters:
bcd - BCD value
Returns:
int value for bcd value

int2bcd

public static int int2bcd(int val)
Convert an int value to a BCD value.

Parameters:
val - int value
Returns:
bcd value for int value

check

public static void check(int bcd)
Check wether a BCD value is correct. If the supplied value contains a nibble with a value >= 10, it will throw an IllegalArgumentException. Otherwise it will simply return.

Parameters:
bcd - number to check

isBcd

public static boolean isBcd(int bcd)
Check wether a BCD value is correct.

Parameters:
bcd - bcd value to check
Returns:
true if supplied value is bcd, otherwise false

base10

public static int base10(int n)
Return the 10 base (10^n).

Parameters:
n - power
Returns:
10^n

correct

public static int correct(int bcd)
Perform a BCD correction. For each nibble that contains a value greater than or equal 10, the next nibble will be incremented. Any overflow is added to the low byte, so an overflow bcd value will toggle even/odd.

Parameters:
bcd - bcd value to correct
Returns:
corrected bcd value

JAPI
Yet another Java API
API Documentation

© 2005-2006 Christian Hujer. All rights reserved. See copyright