From 7fd5b20f76b46c51ace74686fd5fe95d4ed47453 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Fri, 22 Mar 2019 11:22:05 -0700 Subject: [PATCH] 0.2.2 check bad decimal for NaN as well --- package.json | 2 +- src/byte.js | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 27d4506..7c3c864 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/byte.js b/src/byte.js index db1f191..20c2f29 100644 --- a/src/byte.js +++ b/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 }