{"id":196,"date":"2020-11-17T05:19:17","date_gmt":"2020-11-17T05:19:17","guid":{"rendered":"https:\/\/vukieuanh.com\/?p=196"},"modified":"2020-11-17T05:19:17","modified_gmt":"2020-11-17T05:19:17","slug":"literals-an-primitive-casting","status":"publish","type":"post","link":"https:\/\/vukieuanh.net\/index.php\/2020\/11\/17\/literals-an-primitive-casting\/","title":{"rendered":"Literals an Primitive Casting"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">K\u00fd t\u1ef1 s\u1ed1 (Integer literal) c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c bi\u1ec3u di\u1ec5n d\u01b0\u1edbi d\u1ea1ng h\u1ec7 nh\u1ecb ph\u00e2n, h\u1ec7 b\u00e1t ph\u00e2n v\u00e0 h\u1ec7 th\u1eadp l\u1ee5c.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>H\u1ec7 nh\u1ecb ph\u00e2n<\/strong> s\u1ebd \u0111\u01b0\u1ee3c quy \u0111\u1ecbnh nh\u01b0 sau: ti\u1ec1n t\u1ed1 0b l\u00e0 b\u1eaft bu\u1ed9c, sau \u0111\u00f3 \u0111\u1ebfn c\u00e1c k\u00fd t\u1ef1 0 ho\u1eb7c 1, kh\u00f4ng gi\u1edbi h\u1ea1n s\u1ed1<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">v\u00ed d\u1ee5 v\u1ec1 s\u1ed1 nh\u1ecb ph\u00e2n \u0111\u00fang: 0b101010<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">v\u00ed d\u1ee5 v\u1ec1 s\u1ed1 nh\u1ecb ph\u00e2n sai: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">0b120000: c\u00f3 ch\u1ee9a k\u00fd t\u1ef1 kh\u00e1c s\u1ed1 0 v\u00e0 1 sau ph\u1ea7n ti\u1ec1n t\u1ed1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">00b010101: 2 k\u00fd t\u1ef1 \u0111\u1ea7u ti\u00ean kh\u00f4ng ph\u1ea3i l\u00e0 0b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">C\u00f3 m\u1eb9o nh\u1edb \u1edf \u0111\u00e2y \u0111\u1ed1i v\u1edbi m\u00ecnh l\u00e0 ch\u1eef b l\u00e0 ch\u1eef \u0111\u1ea7u c\u1ee7a binary.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">c\u00e1ch t\u00ednh \u0111\u1ed5i t\u1eeb s\u1ed1 nh\u1ecb ph\u00e2n sang s\u1ed1 nguy\u00ean<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">V\u00ed d\u1ee5 s\u1ed1: 0b10101<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u1edf \u0111\u00e2y sau s\u1ed1 b th\u00ec m\u00ecnh s\u1ebd \u0111\u00e1nh s\u1ed1 theo chi\u1ec1u t\u1eeb ph\u1ea3i sang tr\u00e1i l\u00e0 t\u1eeb 0 \u0111\u1ebfn n. Sau \u0111\u00f3 s\u1eed d\u1ee5ng c\u01a1 s\u1ed1 2 v\u1edbi s\u1ed1 m\u0169 t\u01b0\u01a1ng \u1ee9ng. V\u1edbi v\u00ed d\u1ee5 \u1edf tr\u00ean ta s\u1ebd c\u00f3 0b43210 = 1*(2 m\u0169 4) + 0*(2 m\u0169 3) + 1(2 m\u0169 2) + 0(2 m\u0169 1) + 1(2 m\u0169 0)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. <strong>H\u1ec7 b\u00e1t ph\u00e2n<\/strong> s\u1ebd \u0111\u01b0\u1ee3c quy \u0111\u1ecbnh nh\u01b0 sau: ti\u1ec1n t\u1ed1 0 l\u00e0 b\u1eaft bu\u1ed9c, sau \u0111\u00f3 \u0111\u1ebfn c\u00e1c k\u00fd t\u1ef1 t\u1eeb 0 \u0111\u1ebfn 7, kh\u00f4ng gi\u1edbi h\u1ea1n s\u1ed1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">v\u00ed d\u1ee5 v\u1ec1 s\u1ed1 nh\u1ecb ph\u00e2n \u0111\u00fang: 0174154554<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">v\u00ed d\u1ee5 v\u1ec1 s\u1ed1 nh\u1ecb ph\u00e2n sai: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1120000: B\u1eaft \u0111\u1ea7u b\u1eb1ng k\u00fd t\u1ef1 kh\u00f4ng ph\u1ea3i 0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">0173624678: c\u00f3 ch\u1ee9a k\u00fd t\u1ef1 8<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">C\u00f3 m\u1eb9o nh\u1edb \u1edf \u0111\u00e2y \u0111\u1ed1i v\u1edbi m\u00ecnh l\u00e0 s\u1ed1 0 ch\u1eb3ng c\u00f3 \u00fd ngh\u0129a g\u00ec -)))<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">c\u00e1ch t\u00ednh \u0111\u1ed5i t\u1eeb h\u1ec7 b\u00e1t ph\u00e2n sang s\u1ed1 nguy\u00ean<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">V\u00ed d\u1ee5 s\u1ed1: 01543<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u1edf \u0111\u00e2y sau s\u1ed1 b th\u00ec m\u00ecnh s\u1ebd \u0111\u00e1nh s\u1ed1 theo chi\u1ec1u t\u1eeb ph\u1ea3i sang tr\u00e1i l\u00e0 t\u1eeb 0 \u0111\u1ebfn n. Sau \u0111\u00f3 s\u1eed d\u1ee5ng c\u01a1 s\u1ed1 8 v\u1edbi s\u1ed1 m\u0169 t\u01b0\u01a1ng \u1ee9ng. V\u1edbi v\u00ed d\u1ee5 \u1edf tr\u00ean ta s\u1ebd c\u00f3 03210 = 1*(8 m\u0169 3) + 5*(8 m\u0169 2) + 4(8 m\u0169 1) + 3( m\u0169 0) <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. <strong>H\u1ec7 th\u1eadp  l\u1ee5c<\/strong> s\u1ebd \u0111\u01b0\u1ee3c quy \u0111\u1ecbnh nh\u01b0 sau: ti\u1ec1n t\u1ed1 0x l\u00e0 b\u1eaft bu\u1ed9c, sau \u0111\u00f3 \u0111\u1ebfn c\u00e1c k\u00fd t\u1ef1 t\u1eeb 0 \u0111\u1ebfn 9 v\u00e0 t\u1eeb a &#8211; f (t\u01b0\u01a1ng \u1ee9ng v\u1edbi 10-15), kh\u00f4ng gi\u1edbi h\u1ea1n s\u1ed1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">v\u00ed d\u1ee5 v\u1ec1 s\u1ed1 nh\u1ecb ph\u00e2n \u0111\u00fang: 0x157637bcd<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">v\u00ed d\u1ee5 v\u1ec1 s\u1ed1 nh\u1ecb ph\u00e2n sai: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">0x0000hj: ch\u1ee9a k\u00fd t\u1ef1 ngo\u00e0i a-f l\u00e0 h v\u00e0 j<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">073624678: kh\u00f4ng b\u1eaft \u0111\u1ea7u b\u1eb1ng ox<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">C\u00f3 m\u1eb9o nh\u1edb \u1edf \u0111\u00e2y \u0111\u1ed1i v\u1edbi m\u00ecnh l\u00e0 s\u1ed1 x l\u00e0 vi\u1ebft t\u1eaft c\u1ee7a hexadecimal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">c\u00e1ch t\u00ednh \u0111\u1ed5i t\u1eeb h\u1ec7 th\u1eadp l\u1ee5c ph\u00e2n sang s\u1ed1 nguy\u00ean<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">V\u00ed d\u1ee5 s\u1ed1: 0xa1b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u1edf \u0111\u00e2y sau x th\u00ec m\u00ecnh s\u1ebd \u0111\u00e1nh s\u1ed1 theo chi\u1ec1u t\u1eeb ph\u1ea3i sang tr\u00e1i l\u00e0 t\u1eeb 0 \u0111\u1ebfn n. Sau \u0111\u00f3 s\u1eed d\u1ee5ng c\u01a1 s\u1ed1 16 v\u1edbi s\u1ed1 m\u0169 t\u01b0\u01a1ng \u1ee9ng. V\u1edbi v\u00ed d\u1ee5 \u1edf tr\u00ean ta s\u1ebd c\u00f3 ox210 = 10*(16 m\u0169 2) + 1*(16 m\u0169 1) + 11(16 m\u0169 0) <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">V\u1eady th\u00ec v\u1edbi 3 h\u1ec7 s\u1ed1 tr\u00ean ta ho\u00e0n to\u00e0n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng ph\u00e9p so s\u00e1nh nh\u01b0 sau:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>int a = 4;<\/code><br><code>a == 0b100 cho k\u1ebft qu\u1ea3 true<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ti\u1ebfp theo n\u1eefa l\u00e0 ph\u00e9p ++ v\u00e0 ph\u00e9p &#8212; trong  Java l\u00e0 ph\u00e9p d\u1ecbch bit nh\u1ecb ph\u00e2n.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">C\u1ee5 th\u1ec3 n\u1ebfu ta c\u00f3 int a = 4 ngh\u0129a l\u00e0 a \u0111ang \u0111\u01b0\u1ee3c l\u01b0u l\u00e0 0b100. N\u1ebfu ta th\u1ef1c hi\u1ec7n a ++ ngh\u0129a l\u00e0 ta th\u1ef1c hi\u1ec7n d\u1ecbch bit \u1edf \u0111\u00e2y ta s\u1ebd c\u00f3 a l\u00e0 0b101.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">V\u00ec v\u1eady m\u1eb7c d\u00f9ng c\u00e1c b\u1ea1n th\u1ea5y a++ v\u00e0 a = a+1 th\u00ec trong v\u00f2ng l\u1eb7p for ngta v\u1eabn d\u00f9ng a++ v\u00ec ph\u00e9p d\u1ecbch bit n\u00f3 s\u1ebd nhanh h\u01a1n r\u1ea5t r\u1ea5t r\u1ea5t nhi\u1ec1u so v\u1edbi ph\u00e9p g\u00e1n.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">V\u00e0 a = a+1 n\u00f3 ch\u1eb3ng kh\u00e1c g\u00ec so v\u1edbi a = a +10000 c\u1ea3.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">H\u01a1n n\u1eefa ph\u00e9p d\u1ecbch bit th\u00ec c\u00e1c b\u1ea1n ho\u00e0n to\u00e0n c\u00f3 th\u1ec3 th\u1ef1c hi\u1ec7n v\u1edbi ki\u1ec3u <code>bit<\/code> c\u00f2n m\u1ed9t khi c\u00e1c b\u1ea1n s\u1eed d\u1ee5ng a= a+1 r\u1ed3i th\u00ec n\u00f3 ph\u1ea3i l\u00e0 s\u1ed1 int tr\u1edf l\u00ean c\u00e1c b\u1ea1n nh\u00e9.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>K\u00fd t\u1ef1 s\u1ed1 (Integer literal) c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c bi\u1ec3u di\u1ec5n d\u01b0\u1edbi d\u1ea1ng h\u1ec7 nh\u1ecb ph\u00e2n, h\u1ec7 b\u00e1t ph\u00e2n v\u00e0 h\u1ec7 th\u1eadp l\u1ee5c. H\u1ec7 nh\u1ecb ph\u00e2n s\u1ebd \u0111\u01b0\u1ee3c quy \u0111\u1ecbnh nh\u01b0 sau: ti\u1ec1n t\u1ed1 0b l\u00e0 b\u1eaft bu\u1ed9c, sau \u0111\u00f3 \u0111\u1ebfn c\u00e1c k\u00fd t\u1ef1 0 ho\u1eb7c 1, kh\u00f4ng gi\u1edbi h\u1ea1n s\u1ed1 v\u00ed d\u1ee5 v\u1ec1 s\u1ed1 nh\u1ecb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-196","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/vukieuanh.net\/index.php\/wp-json\/wp\/v2\/posts\/196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vukieuanh.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vukieuanh.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vukieuanh.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vukieuanh.net\/index.php\/wp-json\/wp\/v2\/comments?post=196"}],"version-history":[{"count":11,"href":"https:\/\/vukieuanh.net\/index.php\/wp-json\/wp\/v2\/posts\/196\/revisions"}],"predecessor-version":[{"id":273,"href":"https:\/\/vukieuanh.net\/index.php\/wp-json\/wp\/v2\/posts\/196\/revisions\/273"}],"wp:attachment":[{"href":"https:\/\/vukieuanh.net\/index.php\/wp-json\/wp\/v2\/media?parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vukieuanh.net\/index.php\/wp-json\/wp\/v2\/categories?post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vukieuanh.net\/index.php\/wp-json\/wp\/v2\/tags?post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}