BITS_AND_BYTES_15_NOVEMBER_2022_COPY

BITS_AND_BYTES_15_NOVEMBER_2022_COPY

* * *

START OF WEB PAGE COPY

* * *

BITS_AND_BYTES

This single page web application allows the user to click switches which each flip a single uniquely corresponding light bulb from “OFF” to “ON” and vice versa and, also, to click a BINARY_TO_DECIMAL button which computes the binary number represented by the light bulb array configuration at the time that button is clicked. Algebraic equations which are used to convert the base-two integer value represented by the array of eight light bulbs to that base-two integer’s base-ten equivalent value are displayed at the bottom of this web page. (Clicking the RESET button will return this web page to its initial state such that each one of the eight light bulbs is set to “OFF” and all buttons on this web page are set to visible).

Each one of the eight light bulbs which are displayed in the table below (while that light bulb is in its “ON” state) represents two multiplied by itself N times (and N is a nonnegative integer no larger than seven which represents the unique place value of the corresponding light bulb’s binary digit value).

The integer value 0 is an abstract representation of the relatively physical “OFF” (sufficiently low voltage) light bulb state.

The integer value 1 is an abstract representation of the relatively physical “ON” (sufficiently high voltage) light bulb state.

Each of the eight values of N are arranged in descending order starting with N = 7 and ending with N = 0.

The leftmost light bulb has an N value of 7 and that light bulb represents the “highest order bit” in the byte which the light bulb array represents.

highest_order_bit(ON) = 1 * (2 ^ 7) = 1 * 2 * 2 * 2 * 2 * 2 * 2 * 2 = 128.

highest_order_bit(OFF) = 0 * (2 ^ 7) = 0 * 2 * 2 * 2 * 2 * 2 * 2 * 2 = 0.

The rightmost light bulb has an N value of 0 and that light bulb represents the “lowest order bit” in the byte which the light bulb array represents.

lowest_order_bit(ON) = 1 * (2 ^ 0) = 1.

lowest_order_bit(OFF) = 0 * (2 ^ 0) = 0.

(Note that word bit is an abbreviation of the word “binary digit” and that the word byte is an abbreviation of the word “binary term” (and that a binary term is a sequence of exactly 8 binary digits)).

(Note also that a single byte can represent 256 unique patterns and that the largest base-ten value which a byte can represent is 255 and the smallest base-ten value which a byte can represent is 0).

Software Application Files

Hyper-Text-Markup-Language file: https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/binary_to_decimal.html

Portable-Network-Graphics file: https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/light_bulb_off.png

Portable-Network-Graphics file: https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/light_bulb_on.png

Interface Initial (Screenshot Image)

Interface Screenshot Image file: https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/binary_to_decimal_interface_initial.png

Interface Final (Screenshot Image)

Interface Screenshot Image file: https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/binary_to_decimal_interface_final.png

Application Web Page Source Code (Screenshot Image)

Hyper-Text-Markup-Language file: https://github.com/karlinarayberinger/karlina_object_ultimate_starter_pack/blob/main/binary_to_decimal.html

The Hyper-Text-Markup-Language source code defines the web page elements which comprise the user interface component of the BINARY_TO_DECIMAL software application.

Stylesheet Source Code (Preformatted Text)

The Cascading-Style-Sheet source code defines the specifications which control the appearance of the BINARY_TO_DECIMAL web page interface.

/**
* file: karbytes_aesthetic.css
* date: 14_AUGUST_2022
* author: Karlina Ray Beringer
*/

/** Make the page background BLACK, the text orange and monospace, and the page content width 800 pixels or less. */
body {
background: #000000;
color: #ff9000;
font-family: monospace;
font-size: 16px;
width: 800px;
}

/** Make input elements and select elements have an orange rounded border, a BLACK background, and orange monospace text. */
input, select {
background: #000000;
color: #ff9000;
border-color: #ff9000;
border-width: 1px;
border-style: solid;
appearance: none;
font-family: monospace;
font-size: 16px;
}

/** Invert the text color and background color of INPUT and SELECT elements when the cursor (i.e. mouse) hovers over them. */
input:hover, select:hover {
background: #ff9000;
color: #000000;
}

/** Make table data borders one pixel thick and CYAN. Give table data content 10 pixels in padding on all four sides. */
td {
color: #00ffff;
border-color: #00ffff;
border-width: 1px;
border-style: solid;
}

/** Set the text color of elements whose identifier (id) is "output" to CYAN. */
#output {
color: #00ffff;
}

/** Set the text color of elements whose class is "console" to GREEN. Make the text background BLACK. */
.console {
color: #00ff00;
background: #000000;
}

JavaScript Source Code (Preformatted Text)

The JavaScript source code defines the functions which control the behavior of the BINARY_TO_DECIMAL software application.

/**
* file: binary_to_decimal.js
* type: JavaScript
* date: 15_AUGUST_2022
* author: Karlina Ray Beringer
*/

/**
* Display a time stamped message inside of the div element whose id is "output".
*
* Set all light bulbs to "OFF" rather rather than "ON".
*
* Set all binary digit values to zero (0) rather than one (1).
*
* Set all buttons on the web page to visible.
*/
function initialize_application() {
try {
const time_point = Date.now(), p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>';
let light_bulb_off = '<' + 'img src="light_bulb_off.png" width="60"' + '>', i = 0;
const message = "The initialize_application() function was called at time: " + time_point + " milliseconds since 01_JANUARY_1970 00:00:00 (Coordinated Universal Time (UTC)).";
console.log(message);
document.getElementById("output").innerHTML = p0 + message + p1;
for (i = 0; i < 8; i += 1) {
document.getElementById("light_bulb_" + i).innerHTML = light_bulb_off;
document.getElementById("bit_" + i).innerHTML = 0;
document.getElementById("switch_" + i).style.display = "block";
}
document.getElementById("binary_to_decimal_button").style.display = "inline";
}
catch(exception) {
console.log("An exception to expected functioning occurred during the runtime of the JavaScript function named initialize_application(): " + exception);
}
}

/**
* Change the binary state represented by the Nth light bulb in the array of 8 light bulbs to its only alternative state.
*
* If the Nth bit value is set to 0, the Nth light bulb state is assumed to be "OFF".
*
* If the Nth bit value is set to 1, the Nth light bulb state is assumed to be "ON".
*
* When the switch for the Nth light bulb is clicked, the following will occur:
*
* If the Nth bit is set to 0, then the Nth bit will be set to 1 and the Nth light bulb state will be set to "ON".
*
* Otherwise, the Nth bit will be set to 0 and the Nth light bulb state will be set to "OFF".
*
* @param {Number} N is assumed to be a base-ten integer no smaller than 0 and no larger than 7.
*/
function binary_switch(N) {
try {
let p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>', bit = undefined, light_bulb_image = undefined, light_bulb_off = '<' + 'img src="light_bulb_off.png" width="60"' + '>', light_bulb_on = '<' + 'img src="light_bulb_on.png" width="60"' + '>';
bit = parseInt(document.getElementById("bit_" + N).innerHTML);
if (bit === 0) {
document.getElementById("bit_" + N).innerHTML = 1;
document.getElementById("light_bulb_" + N).innerHTML = light_bulb_on;
}
else {
document.getElementById("bit_" + N).innerHTML = 0;
document.getElementById("light_bulb_" + N).innerHTML = light_bulb_off;
}
}
catch(exception) {
console.log("An exception to expected functioning occurred during the runtime of the JavaScript function named binary_switch(N): " + exception);
}
}

/**
* Change the binary state represented by the 7th (i.e. seventh) light bulb in the array of 8 light bulbs to its only alternative state.
*
* Note that the 7th light bulb represents the highest order bit and is the leftmost light bulb in the array.
*
* If the 7th bit value is set to 0, the 7th light bulb state is assumed to be "OFF".
*
* If the 7th bit value is set to 1, the 7th light bulb state is assumed to be "ON".
*
* When the switch for the 7th light bulb is clicked, the following will occur:
*
* If the 7th bit is set to 0, then the Nth bit will be set to 1 and the 7th light bulb state will be set to "ON".
*
* Otherwise, the 7th bit will be set to 0 and the 7th light bulb state will be set to "OFF".
*/
function switch_7() {
const time_point = Date.now();
console.log("The switch_7 button was clicked at time: " + time_point + " milliseconds since 01_JANUARY_1970 00:00:00 (Coordinated Universal Time (UTC)).");
binary_switch(7);
}

/**
* Change the binary state represented by the 6th (i.e. sixth) light bulb in the array of 8 light bulbs to its only alternative state.
*
* If the 6th bit value is set to 0, the 6th light bulb state is assumed to be "OFF".
*
* If the 6th bit value is set to 1, the 6th light bulb state is assumed to be "ON".
*
* When the switch for the 6th light bulb is clicked, the following will occur:
*
* If the 6th bit is set to 0, then the 6th bit will be set to 1 and the 6th light bulb state will be set to "ON".
*
* Otherwise, the 6th bit will be set to 0 and the 6th light bulb state will be set to "OFF".
*/
function switch_6() {
const time_point = Date.now();
console.log("The switch_6 button was clicked at time: " + time_point + " milliseconds since 01_JANUARY_1970 00:00:00 (Coordinated Universal Time (UTC)).");
binary_switch(6);
}

/**
* Change the binary state represented by the 5th (i.e. fifth) light bulb in the array of 8 light bulbs to its only alternative state.
*
* If the 5th bit value is set to 0, the 5th light bulb state is assumed to be "OFF".
*
* If the 5th bit value is set to 1, the 5th light bulb state is assumed to be "ON".
*
* When the switch for the 5th light bulb is clicked, the following will occur:
*
* If the 5th bit is set to 0, then the 5th bit will be set to 1 and the 5th light bulb state will be set to "ON".
*
* Otherwise, the 5th bit will be set to 0 and the 5th light bulb state will be set to "OFF".
*/
function switch_5() {
const time_point = Date.now();
console.log("The switch_5 button was clicked at time: " + time_point + " milliseconds since 01_JANUARY_1970 00:00:00 (Coordinated Universal Time (UTC)).");
binary_switch(5);
}

/**
* Change the binary state represented by the 4th (i.e. fourth) light bulb in the array of 8 light bulbs to its only alternative state.
*
* If the 4th bit value is set to 0, the 4th light bulb state is assumed to be "OFF".
*
* If the 4th bit value is set to 1, the 4th light bulb state is assumed to be "ON".
*
* When the switch for the 4th light bulb is clicked, the following will occur:
*
* If the 4th bit is set to 0, then the 4th bit will be set to 1 and the 4th light bulb state will be set to "ON".
*
* Otherwise, the 4th bit will be set to 0 and the 4th light bulb state will be set to "OFF".
*/
function switch_4() {
const time_point = Date.now();
console.log("The switch_4 button was clicked at time: " + time_point + " milliseconds since 01_JANUARY_1970 00:00:00 (Coordinated Universal Time (UTC)).");
binary_switch(4);
}

/**
* Change the binary state represented by the 3rd (i.e. third) light bulb in the array of 8 light bulbs to its only alternative state.
*
* If the 3rd bit value is set to 0, the 3rd light bulb state is assumed to be "OFF".
*
* If the 3rd bit value is set to 1, the 3rd light bulb state is assumed to be "ON".
*
* When the switch for the 3rd light bulb is clicked, the following will occur:
*
* If the 3rd bit is set to 0, then the 3rd bit will be set to 1 and the 3rd light bulb state will be set to "ON".
*
* Otherwise, the 3rd bit will be set to 0 and the 3rd light bulb state will be set to "OFF".
*/
function switch_3() {
const time_point = Date.now();
console.log("The switch_3 button was clicked at time: " + time_point + " milliseconds since 01_JANUARY_1970 00:00:00 (Coordinated Universal Time (UTC)).");
binary_switch(3);
}

/**
* Change the binary state represented by the 2nd (i.e. second) light bulb in the array of 8 light bulbs to its only alternative state.
*
* If the 2nd bit value is set to 0, the 2nd light bulb state is assumed to be "OFF".
*
* If the 2nd bit value is set to 1, the 2nd light bulb state is assumed to be "ON".
*
* When the switch for the 2nd light bulb is clicked, the following will occur:
*
* If the 2nd bit is set to 0, then the 2nd bit will be set to 1 and the 2nd light bulb state will be set to "ON".
*
* Otherwise, the 2nd bit will be set to 0 and the 2nd light bulb state will be set to "OFF".
*/
function switch_2() {
const time_point = Date.now();
console.log("The switch_2 button was clicked at time: " + time_point + " milliseconds since 01_JANUARY_1970 00:00:00 (Coordinated Universal Time (UTC)).");
binary_switch(2);
}

/**
* Change the binary state represented by the 1st (i.e. first) light bulb in the array of 8 light bulbs to its only alternative state.
*
* If the 1st bit value is set to 0, the 1st light bulb state is assumed to be "OFF".
*
* If the 1st bit value is set to 1, the 1st light bulb state is assumed to be "ON".
*
* When the switch for the 1st light bulb is clicked, the following will occur:
*
* If the 1st bit is set to 0, then the 1st bit will be set to 1 and the 1st light bulb state will be set to "ON".
*
* Otherwise, the 1st bit will be set to 0 and the 1st light bulb state will be set to "OFF".
*/
function switch_1() {
const time_point = Date.now();
console.log("The switch_1 button was clicked at time: " + time_point + " milliseconds since 01_JANUARY_1970 00:00:00 (Coordinated Universal Time (UTC)).");
binary_switch(1);
}

/**
* Change the binary state represented by the 0th (i.e. zeroth) light bulb in the array of 8 light bulbs to its only alternative state.
*
* Note that the 0th light bulb represents the lowest order bit and is the rightmost light bulb in the array.
*
* If the 0th bit value is set to 0, the 0th light bulb state is assumed to be "OFF".
*
* If the 0th bit value is set to 1, the 0th light bulb state is assumed to be "ON".
*
* When the switch for the 1st light bulb is clicked, the following will occur:
*
* If the 0th bit is set to 0, then the 0th bit will be set to 1 and the 1st light bulb state will be set to "ON".
*
* Otherwise, the 0th bit will be set to 0 and the 0th light bulb state will be set to "OFF".
*/
function switch_0() {
const time_point = Date.now();
console.log("The switch_0 button was clicked at time: " + time_point + " milliseconds since 01_JANUARY_1970 00:00:00 (Coordinated Universal Time (UTC)).");
binary_switch(0);
}

/**
* Hide all buttons except for the RESET button.
*
* Convert the input binary number to its logically equivalent decimal number and display the arithmetic steps inside the div whose id is "output".
*/
function binary_to_decimal() {
try {
const time_point = Date.now(), p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>', s0 = '<' + 'span class="console"' + '>', s1 = '<' + '/' + 'span' + '>';
let i = 0, binary_digits_string = "", decimal_output_number = 0, decimal_term_value = 0,  arithmetic_steps = "", message = "";
message = "The BINARY_TO_DECIMAL button was clicked at time: " + time_point + " milliseconds since 01_JANUARY_1970 00:00:00 (Coordinated Universal Time (UTC)).";
console.log(message);
document.getElementById("output").innerHTML += p0 + message + p1;
for (i = 0; i < 8; i += 1) document.getElementById("switch_" + i).style.display = "none";
document.getElementById("binary_to_decimal_button").style.display = "none";
for (i = 7; i > -1; i -= 1) binary_digits_string += document.getElementById("bit_" + i).innerHTML;
console.log("The input binary digit sequence is " + binary_digits_string + ".");
for (i = 7; i > -1; i -= 1) {
decimal_term_value = parseInt(binary_digits_string[i]) * Math.pow(2, 7 - i);
decimal_output_number += decimal_term_value;

}
console.log("The output decimal digit sequence is " + decimal_output_number + ".");
arithmetic_steps += p0 + "binary_input: " + s0 + binary_digits_string + s1 + "." + p1;
arithmetic_steps += p0 + "decimal_output: " + decimal_output_number + "." + p1;
arithmetic_steps += p0 + "arithmetic_steps: " + p1;
arithmetic_steps += p0 + decimal_output_number + " = " + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[0] + s1 + " * (2 ^ 7)) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[1] + s1 + " * (2 ^ 6)) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[2] + s1 + " * (2 ^ 5)) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[3] + s1 + " * (2 ^ 4)) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[4] + s1 + " * (2 ^ 3)) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[5] + s1 + " * (2 ^ 2)) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[6] + s1 + " * (2 ^ 1)) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[7] + s1 + " * (2 ^ 0)) = " + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[0] + s1 + " * 128) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[1] + s1 + " * 64) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[2] + s1 + " * 32) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[3] + s1 + " * 16) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[4] + s1 + " * 8) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[5] + s1 + " * 4) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[6] + s1 + " * 2) +" + p1;
arithmetic_steps += p0 + "(" + s0 + binary_digits_string[7] + s1 + " * 1) = " + p1;
arithmetic_steps += p0 + parseInt(binary_digits_string[0]) * 128 + " + " + p1;
arithmetic_steps += p0 + parseInt(binary_digits_string[1]) * 64 + " + " + p1;
arithmetic_steps += p0 + parseInt(binary_digits_string[2]) * 32 + " + " + p1;
arithmetic_steps += p0 + parseInt(binary_digits_string[3]) * 16 + " + " + p1;
arithmetic_steps += p0 + parseInt(binary_digits_string[4]) * 8 + " + " + p1;
arithmetic_steps += p0 + parseInt(binary_digits_string[5]) * 4 + " + " + p1;
arithmetic_steps += p0 + parseInt(binary_digits_string[6]) * 2 + " + " + p1;
arithmetic_steps += p0 + parseInt(binary_digits_string[7]) * 1 + "." + p1;
document.getElementById("output").innerHTML += arithmetic_steps;
}
catch(exception) {
console.log("An exception to expected functioning occurred during the runtime of the JavaScript function named binary_to_decimal(): " + exception);
}
}

This web page was last updated on 15_AUGUST_2022. The content displayed on this web page is licensed as PUBLIC_DOMAIN intellectual property.

* * *

END OF WEB PAGE COPY

* * *

This web page was last updated on 15_NOVEMBER_2022. The content displayed on this web page is licensed as PUBLIC_DOMAIN intellectual property.