5 kyu

isInt32(int, byteLength)

122 of 123wthit56

Description:

Write a function that returns true if a given value is a true Int32 integer. It should accept two arguments:

  • int this value is the basis for any testing done. It should be a primitive 32-bit integer number value. (Be careful: JavaScript can have 64-bit floats that happen to have no decimal place, and so may look like integers. These are not valid Int32 values.)
  • byteLength is an optional value (may be omitted or be a null or undefined value). If provided, it will be a primitive integer from 0 to 32. For the int to be valid, it should have no data (1s) beyond (byteLength) bits, counting from right to left.

Example:

int = 5, byteLength = 5
int == 00000000000000000000000000000101 // binary
//                                ^^^^^ // 5 bits from the end
// so the "byte" looks like: 00101
// there are no 1s outside the "byte," so...
isInt32(/* int: */ 5, /* byteLength: */ 5) == true

int = 16, byteLength = 3
int == 00000000000000000000000000010000 // binary
//                                  ^^^ // 3 bits from the end
// so the "byte" looks like: 000
// there is one 1 outside the "byte," so...
isInt32(/* int: */ 16, /* byteLength: */ 3) == false

int = -1, byteLength = 28
int == 11111111111111111111111111111111 // binary
//         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // 28 bits from the end
// so the "byte" looks like: 1111111111111111111111111111
// there are four 1s outside the "byte," so...
isInt32(/* int: */ -1, /* byteLength: */ 28) == false
Bits
Fundamentals

Stats:

CreatedJun 3, 2014
PublishedJun 3, 2014
Warriors Trained602
Total Skips446
Total Code Submissions3893
Total Times Completed123
JavaScript Completions122
Total Stars8
% of votes with a positive feedback rating77% of 45
Total "Very Satisfied" Votes29
Total "Somewhat Satisfied" Votes11
Total "Not Satisfied" Votes5
Ad
Contributors
  • wthit56 Avatar
  • myjinxin2015 Avatar
  • Voile Avatar
Ad