0.2.2 check bad decimal for NaN as well
parent
fd40a27dae
commit
7fd5b20f76
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@uci-utils/byte",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.2",
|
||||
"description": "Byte Class and related functions",
|
||||
"main": "src/byte.js",
|
||||
"scripts": {
|
||||
|
|
11
src/byte.js
11
src/byte.js
|
@ -110,11 +110,13 @@ class Byte {
|
|||
bwop = bits.and
|
||||
break
|
||||
}
|
||||
log.debug({msg:'byte and state as passed', byte:byte, value:this.value})
|
||||
// console.log({msg:'byte and state as passed', op:op, byte:byteFormat(byte, { in: format.in, out: 'ARY' }), value:this.toFmt('ARY')})
|
||||
log.debug({msg:'byte and state as passed', byte:byte, value:this.value, })
|
||||
let opbyte = bwop(
|
||||
this.toFmt('ARY'),
|
||||
byteFormat(byte, { in: format.in, out: 'ARY' })
|
||||
)
|
||||
// console.log('>>>>',opbyte)
|
||||
return byteFormat(opbyte, { in: 'ARY', out: format.out })
|
||||
}
|
||||
|
||||
|
@ -246,7 +248,7 @@ export { Byte, byteFormat, BYTE_FORMATS, bitsReverse, bitChanges, stateChanges }
|
|||
const format = function(byte, fmt) {
|
||||
let ifmt = fmt.in || 'STR' // default STR
|
||||
let ofmt = fmt.out || 'DEC' // default DEC
|
||||
// debug.L2('input: ', byte, ' input format: ', ifmt, ' output format:', ofmt);
|
||||
log.debug('input: ', byte, ' input format: ', ifmt, ' output format:', ofmt)
|
||||
|
||||
let decimal = 0
|
||||
switch (ifmt) {
|
||||
|
@ -272,9 +274,8 @@ const format = function(byte, fmt) {
|
|||
ofmt = false
|
||||
break
|
||||
}
|
||||
|
||||
if ( decimal<0 || decimal >255) {
|
||||
log.warn ({byte:byte, fmt:fmt, msg:'error - invalid byte - not able to convert to decmial, converting to 0'})
|
||||
if ( decimal<0 || decimal >255 || isNaN(decimal)) {
|
||||
log.warn ({decimal:decimal, byte:byte, fmt:fmt, msg:'error - invalid byte - not able to convert to decmial, converting to 0'})
|
||||
decimal = 0
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue