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