Variable = BCD2BIN(bcdvalue)
| Variable | Variable to store results (returns Long) |
| bcdvalue | BCD value to convert to binary |
Bcd2Bin converts a BCD (Binary Coded Decimal) number into a normal binary number, CUBLOC BASIC's default number format. BCD is a way of expressing values as decimals. For example, the number 3451 in binary is as shown below:
<html> <svg version=“1.2” baseProfile=“tiny” width=“59.82mm” height=“23.16mm” viewBox=“1114 1097 5982 2316” preserveAspectRatio=“xMidYMid” fill-rule=“evenodd” stroke-width=“28.222” stroke-linejoin=“round” xmlns=“http://www.w3.org/2000/svg” xmlns:xlink=“http://www.w3.org/1999/xlink” xml:space=“preserve”> <defs>
<font id="EmbeddedFont_1" horiz-adv-x="2048"> <font-face font-family="Arial embedded" units-per-em="2048" font-weight="normal" font-style="normal" ascent="1852" descent="450"/> <missing-glyph horiz-adv-x="2048" d="M 0,0 L 2047,0 2047,2047 0,2047 0,0 Z"/> <glyph unicode="D" horiz-adv-x="1191" d="M 158,0 L 158,1466 663,1466 C 777,1466 864,1459 924,1445 1008,1426 1080,1391 1139,1340 1216,1275 1274,1191 1313,1090 1351,988 1370,872 1370,741 1370,630 1357,531 1331,445 1305,359 1272,288 1231,232 1190,175 1146,131 1098,99 1049,66 991,42 923,25 854,8 776,0 687,0 L 158,0 Z M 352,173 L 665,173 C 762,173 838,182 893,200 948,218 991,243 1024,276 1070,322 1106,384 1132,462 1157,539 1170,633 1170,744 1170,897 1145,1015 1095,1098 1044,1180 983,1235 911,1263 859,1283 775,1293 660,1293 L 352,1293 352,173 Z"/> <glyph unicode="B" horiz-adv-x="1086" d="M 150,0 L 150,1466 700,1466 C 812,1466 902,1451 970,1422 1037,1392 1090,1346 1129,1285 1167,1223 1186,1158 1186,1091 1186,1028 1169,969 1135,914 1101,859 1050,814 981,780 1070,754 1138,710 1186,647 1233,584 1257,510 1257,425 1257,356 1243,293 1214,234 1185,175 1149,129 1106,97 1063,65 1010,41 946,25 881,8 802,0 709,0 L 150,0 Z M 344,850 L 661,850 C 747,850 809,856 846,867 895,882 933,906 958,940 983,974 995,1017 995,1068 995,1117 983,1160 960,1197 937,1234 903,1259 860,1273 817,1286 742,1293 637,1293 L 344,1293 344,850 Z M 344,173 L 709,173 C 772,173 816,175 841,180 886,188 923,201 953,220 983,239 1008,266 1027,302 1046,337 1056,378 1056,425 1056,480 1042,527 1014,568 986,608 947,636 898,653 848,669 776,677 683,677 L 344,677 344,173 Z"/> <glyph unicode="7" horiz-adv-x="954" d="M 97,1274 L 97,1447 1046,1447 1046,1307 C 953,1208 860,1076 769,911 677,746 606,577 556,403 520,280 497,146 487,0 L 302,0 C 304,115 327,255 370,418 413,581 476,739 557,891 638,1042 724,1170 815,1274 L 97,1274 Z"/> <glyph unicode="5" horiz-adv-x="954" d="M 85,384 L 274,400 C 288,308 321,239 372,193 423,146 484,123 556,123 643,123 716,156 776,221 836,286 866,373 866,481 866,584 837,665 780,724 722,783 646,813 553,813 495,813 443,800 396,774 349,747 313,713 286,671 L 117,693 259,1446 988,1446 988,1274 403,1274 324,880 C 412,941 504,972 601,972 729,972 837,928 925,839 1013,750 1057,636 1057,497 1057,364 1018,250 941,153 847,34 719,-25 556,-25 423,-25 314,12 230,87 145,162 97,261 85,384 Z"/> <glyph unicode="4" horiz-adv-x="1007" d="M 662,0 L 662,351 26,351 26,516 695,1466 842,1466 842,516 1040,516 1040,351 842,351 842,0 662,0 Z M 662,516 L 662,1177 203,516 662,516 Z"/> <glyph unicode="3" horiz-adv-x="954" d="M 86,387 L 266,411 C 287,309 322,236 372,191 421,146 482,123 553,123 638,123 709,152 768,211 826,270 855,342 855,429 855,512 828,580 774,634 720,687 651,714 568,714 534,714 492,707 441,694 L 461,852 C 473,851 483,850 490,850 567,850 636,870 697,910 758,950 789,1012 789,1095 789,1161 767,1216 722,1259 677,1302 620,1324 549,1324 479,1324 421,1302 374,1258 327,1214 297,1148 284,1060 L 104,1092 C 126,1213 176,1306 254,1373 332,1439 429,1472 545,1472 625,1472 699,1455 766,1421 833,1386 885,1339 921,1280 956,1221 974,1158 974,1091 974,1028 957,970 923,918 889,866 839,825 772,794 859,774 926,733 974,670 1022,607 1046,528 1046,433 1046,305 999,197 906,108 813,19 695,-26 552,-26 423,-26 317,12 232,89 147,166 98,265 86,387 Z"/> <glyph unicode="1" horiz-adv-x="530" d="M 763,0 L 583,0 583,1147 C 540,1106 483,1064 413,1023 342,982 279,951 223,930 L 223,1104 C 324,1151 412,1209 487,1276 562,1343 616,1409 647,1472 L 763,1472 763,0 Z"/> <glyph unicode="0" horiz-adv-x="954" d="M 85,723 C 85,896 103,1036 139,1142 174,1247 227,1329 298,1386 368,1443 456,1472 563,1472 642,1472 711,1456 770,1425 829,1393 878,1347 917,1288 956,1228 986,1155 1008,1070 1030,984 1041,868 1041,723 1041,551 1023,412 988,307 953,201 900,119 830,62 759,4 670,-25 563,-25 422,-25 311,26 230,127 133,249 85,448 85,723 Z M 270,723 C 270,482 298,322 355,243 411,163 480,123 563,123 646,123 715,163 772,243 828,323 856,483 856,723 856,964 828,1125 772,1204 715,1283 645,1323 561,1323 478,1323 412,1288 363,1218 301,1129 270,964 270,723 Z"/> <glyph unicode=" " horiz-adv-x="556"/> </font>
</defs> <g visibility=“visible” id=“Slide_1”>
<g id="Drawing_1"> <g fill="rgb(31,26,23)" stroke="none" font-family="Arial embedded" font-size="803" font-style="normal" font-weight="400"> <text x="3086" y="1710"> <tspan x="3086 3532 3758 4204 4423 4869 5096">3 4 5 1</tspan></text> </g> <g fill="rgb(31,26,23)" stroke="none" font-family="Arial embedded" font-size="575" font-style="normal" font-weight="400"> <text x="1650" y="3376">0</text> <text fill="rgb(31,26,23)" stroke="none" x="3214" y="3354">D</text> <text fill="rgb(31,26,23)" stroke="none" x="4778" y="3338">7</text> <text fill="rgb(31,26,23)" stroke="none" x="6342" y="3316">B</text> </g> <g fill="rgb(31,26,23)" stroke="none" font-family="Arial embedded" font-size="386" font-style="normal" font-weight="400"> <text x="1220" y="2369"> <tspan x="1220 1432 1537 1749 1855 2074 2180 2391 2497 2603 2709 2920 3026 3238 3343 3562 3668 3880 3986 4091 4197 4303 4514 4620 4832 4938 5157 5262 5474 5580 5686 5791 6003 6109 6320 6426 6638 6751">0 0 0 0 1 1 0 1 0 1 1 1 1 0 1 1</tspan></text> <path fill="none" stroke="none" d="M 1326,2770 L 2368,2770 2368,2551 1326,2551 1326,2770 Z"/> <path stroke-width="15" fill="none" stroke="rgb(31,26,23)" d="M 1326,2770 L 2368,2770 2368,2551 1326,2551 1326,2770 Z"/> <path fill="none" stroke="none" d="M 2836,2778 L 3871,2778 3871,2551 2836,2551 2836,2778 Z"/> <path stroke-width="15" fill="none" stroke="rgb(31,26,23)" d="M 2836,2778 L 3871,2778 3871,2551 2836,2551 2836,2778 Z"/> <path fill="none" stroke="none" d="M 4340,2778 L 5382,2778 5382,2558 4340,2558 4340,2778 Z"/> <path stroke-width="15" fill="none" stroke="rgb(31,26,23)" d="M 4340,2778 L 5382,2778 5382,2558 4340,2558 4340,2778 Z"/> <path fill="none" stroke="none" d="M 5843,2786 L 6885,2786 6885,2558 5843,2558 5843,2786 Z"/> <path stroke-width="15" fill="none" stroke="rgb(31,26,23)" d="M 5843,2786 L 6885,2786 6885,2558 5843,2558 5843,2786 Z"/> <path fill="rgb(255,255,255)" stroke="none" d="M 1152,2649 L 7059,2649 7059,2490 1152,2490 1152,2649 Z"/> <path stroke-width="7" fill="none" stroke="none" d="M 1152,2649 L 7059,2649 7059,2490 1152,2490 1152,2649 Z"/> </g> </g>
</g> </svg> </html>
The following is 3451 converted to BCD code. As you can see, each 4 bits represent one of the digits.
<html> <svg version=“1.2” baseProfile=“tiny” width=“60.66mm” height=“25.4mm” viewBox=“1130 1100 6066 2540” preserveAspectRatio=“xMidYMid” fill-rule=“evenodd” stroke-width=“28.222” stroke-linejoin=“round” xmlns=“http://www.w3.org/2000/svg” xmlns:xlink=“http://www.w3.org/1999/xlink” xml:space=“preserve”> <defs>
<font id="EmbeddedFont_1" horiz-adv-x="2048"> <font-face font-family="Arial embedded" units-per-em="2048" font-weight="normal" font-style="normal" ascent="1852" descent="450"/> <missing-glyph horiz-adv-x="2048" d="M 0,0 L 2047,0 2047,2047 0,2047 0,0 Z"/> <glyph unicode="5" horiz-adv-x="954" d="M 85,384 L 274,400 C 288,308 321,239 372,193 423,146 484,123 556,123 643,123 716,156 776,221 836,286 866,373 866,481 866,584 837,665 780,724 722,783 646,813 553,813 495,813 443,800 396,774 349,747 313,713 286,671 L 117,693 259,1446 988,1446 988,1274 403,1274 324,880 C 412,941 504,972 601,972 729,972 837,928 925,839 1013,750 1057,636 1057,497 1057,364 1018,250 941,153 847,34 719,-25 556,-25 423,-25 314,12 230,87 145,162 97,261 85,384 Z"/> <glyph unicode="4" horiz-adv-x="1007" d="M 662,0 L 662,351 26,351 26,516 695,1466 842,1466 842,516 1040,516 1040,351 842,351 842,0 662,0 Z M 662,516 L 662,1177 203,516 662,516 Z"/> <glyph unicode="3" horiz-adv-x="954" d="M 86,387 L 266,411 C 287,309 322,236 372,191 421,146 482,123 553,123 638,123 709,152 768,211 826,270 855,342 855,429 855,512 828,580 774,634 720,687 651,714 568,714 534,714 492,707 441,694 L 461,852 C 473,851 483,850 490,850 567,850 636,870 697,910 758,950 789,1012 789,1095 789,1161 767,1216 722,1259 677,1302 620,1324 549,1324 479,1324 421,1302 374,1258 327,1214 297,1148 284,1060 L 104,1092 C 126,1213 176,1306 254,1373 332,1439 429,1472 545,1472 625,1472 699,1455 766,1421 833,1386 885,1339 921,1280 956,1221 974,1158 974,1091 974,1028 957,970 923,918 889,866 839,825 772,794 859,774 926,733 974,670 1022,607 1046,528 1046,433 1046,305 999,197 906,108 813,19 695,-26 552,-26 423,-26 317,12 232,89 147,166 98,265 86,387 Z"/> <glyph unicode="1" horiz-adv-x="530" d="M 763,0 L 583,0 583,1147 C 540,1106 483,1064 413,1023 342,982 279,951 223,930 L 223,1104 C 324,1151 412,1209 487,1276 562,1343 616,1409 647,1472 L 763,1472 763,0 Z"/> <glyph unicode="0" horiz-adv-x="954" d="M 85,723 C 85,896 103,1036 139,1142 174,1247 227,1329 298,1386 368,1443 456,1472 563,1472 642,1472 711,1456 770,1425 829,1393 878,1347 917,1288 956,1228 986,1155 1008,1070 1030,984 1041,868 1041,723 1041,551 1023,412 988,307 953,201 900,119 830,62 759,4 670,-25 563,-25 422,-25 311,26 230,127 133,249 85,448 85,723 Z M 270,723 C 270,482 298,322 355,243 411,163 480,123 563,123 646,123 715,163 772,243 828,323 856,483 856,723 856,964 828,1125 772,1204 715,1283 645,1323 561,1323 478,1323 412,1288 363,1218 301,1129 270,964 270,723 Z"/> <glyph unicode=" " horiz-adv-x="556"/> </font>
</defs> <g visibility=“visible” id=“Slide_1”>
<g id="Drawing_1"> <g fill="rgb(31,26,23)" stroke="none" font-family="Arial embedded" font-size="814" font-style="normal" font-weight="400"> <text x="3022" y="1722"> <tspan x="3022 3474 3704 4156 4378 4830 5060">3 4 5 1</tspan></text> </g> <g fill="rgb(31,26,23)" stroke="none" font-family="Arial embedded" font-size="583" font-style="normal" font-weight="400"> <text x="1674" y="3603">3</text> <text fill="rgb(31,26,23)" stroke="none" x="3260" y="3580">4</text> <text fill="rgb(31,26,23)" stroke="none" x="4845" y="3564">5</text> <text fill="rgb(31,26,23)" stroke="none" x="6431" y="3541">1</text> </g> <g fill="rgb(31,26,23)" stroke="none" font-family="Arial embedded" font-size="391" font-style="normal" font-weight="400"> <text x="1283" y="2605"> <tspan x="1283 1498 1605 1819 1927 2149 2256 2471 2578 2685 2792 3007 3114 3329 3436 3658 3765 3980 4087 4195 4302 4409 4624 4731 4946 5053 5275 5382 5597 5704 5811 5919 6133 6240 6455 6562 6777 6892">0 0 1 1 0 1 0 0 0 1 0 1 0 0 0 1</tspan></text> <path fill="none" stroke="none" d="M 1345,2988 L 2402,2988 2402,2766 1345,2766 1345,2988 Z"/> <path stroke-width="15" fill="none" stroke="rgb(31,26,23)" d="M 1345,2988 L 2402,2988 2402,2766 1345,2766 1345,2988 Z"/> <path fill="none" stroke="none" d="M 2877,2996 L 3926,2996 3926,2766 2877,2766 2877,2996 Z"/> <path stroke-width="15" fill="none" stroke="rgb(31,26,23)" d="M 2877,2996 L 3926,2996 3926,2766 2877,2766 2877,2996 Z"/> <path fill="none" stroke="none" d="M 4401,2996 L 5458,2996 5458,2773 4401,2773 4401,2996 Z"/> <path stroke-width="15" fill="none" stroke="rgb(31,26,23)" d="M 4401,2996 L 5458,2996 5458,2773 4401,2773 4401,2996 Z"/> <path fill="none" stroke="none" d="M 5925,3004 L 6982,3004 6982,2773 5925,2773 5925,3004 Z"/> <path stroke-width="15" fill="none" stroke="rgb(31,26,23)" d="M 5925,3004 L 6982,3004 6982,2773 5925,2773 5925,3004 Z"/> <path fill="rgb(255,255,255)" stroke="none" d="M 1168,2866 L 7159,2866 7159,2704 1168,2704 1168,2866 Z"/> <path stroke-width="8" fill="none" stroke="none" d="M 1168,2866 L 7159,2866 7159,2704 1168,2704 1168,2866 Z"/> </g> </g>
</g> </svg> </html>
This command is useful when the user needs to convert a variable for a device such as a 7 segment display, or a real-time clock.
Dim A As Integer A = Bcd2bin(&h1234) Debug Dec A ' Print 1234
See also Bin2Bcd