Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

signed and unsigned integers in JavaScript

var UInt4 = function (value) {
	return (value & 0xF);
};

var Int4 = function (value) {
	var ref = UInt4(value);
	return (ref > 0x7) ? ref - 0x10 : ref;
};

var UInt8 = function (value) {
	return (value & 0xFF);
};

var Int8 = function (value) {
	var ref = UInt8(value);
	return (ref > 0x7F) ? ref - 0x100 : ref;
};

var UInt16 = function (value) {
	return (value & 0xFFFF);
};

var Int16 = function (value) {
	var ref = UInt16(value);
	return (ref > 0x7FFF) ? ref - 0x10000 : ref;
};

console.log ("
4-bit");
var value = 8;
console.log ("value:		" + value);
console.log ("unsigned:	" + UInt4(value));
console.log ("signed:		" + Int4(value));

console.log ("
8-bit");
var value = 128;
console.log ("value:		" + value);
console.log ("unsigned:	" + UInt8(value));
console.log ("signed:		" + Int8(value));

console.log ("
16-bit");
var value = 32798;
console.log ("value:		" + value);
console.log ("unsigned:	" + UInt16(value));
console.log ("signed:		" + Int16(value));
Comment

PREVIOUS NEXT
Code Example
Javascript :: ion icon react 
Javascript :: multiple queries in node js 
Javascript :: jquery get table to object 
Javascript :: express js sample project 
Javascript :: react particles react 
Javascript :: numero random en js 
Javascript :: Unable to resolve "@react-native-community/masked-view" from 
Javascript :: how to remove last element from array in javascript 
Javascript :: angular httpclient post body 
Javascript :: jquery get value of td by class 
Javascript :: javascript function return boolean 
Javascript :: cloudwatch logs sdk. 
Javascript :: javascript trim whitespace 
Javascript :: is palindrome 
Javascript :: react input cursor jump end 
Javascript :: remove a value to an array of javascript 
Javascript :: simplexml format xml 
Javascript :: two sum js 
Javascript :: overflowx 
Javascript :: is promise 
Javascript :: monaco editor get value 
Javascript :: random number generatoe js 
Javascript :: js check data type 
Javascript :: jquery datatable update row cell value 
Javascript :: react materialize cdn 
Javascript :: evento tecla enter javascript 
Javascript :: loop through async javascript -4 
Javascript :: javascript good practice 
Javascript :: how to run node js with proxy 
Javascript :: parsedate javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =