{"id":124642,"date":"2024-07-08T11:59:49","date_gmt":"2024-07-08T08:59:49","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=124642"},"modified":"2024-07-08T11:59:51","modified_gmt":"2024-07-08T08:59:51","slug":"convert-short-to-byte-array","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html","title":{"rendered":"Convert Short to Byte Array"},"content":{"rendered":"<h2 class=\"wp-block-heading\">1. Introduction<\/h2>\n<p>Converting a short value to a byte array is a common task when dealing with binary data. In this example, I will demonstrate short byte array conversion in the following ways:<\/p>\n<ul class=\"wp-block-list\">\n<li>Using <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/ByteBuffer.html\" target=\"_blank\" rel=\"noreferrer noopener\">java.nio.ByteBuffer<\/a>&#8216;s <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/ByteBuffer.html#array--\" target=\"_blank\" rel=\"noreferrer noopener\">array<\/a> method.<\/li>\n<li>Using <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/io\/ByteArrayOutputStream.html\" target=\"_blank\" rel=\"noreferrer noopener\">java.io.ByteArrayOutputStream<\/a>&#8216;s <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/io\/ByteArrayOutputStream.html#toByteArray--\" target=\"_blank\" rel=\"noreferrer noopener\">toByteArray<\/a> method.<\/li>\n<li>Using the <a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/nutsandbolts\/op3.html\" target=\"_blank\" rel=\"noreferrer noopener\">signed right shift operator &gt;&gt;<\/a>.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">2. Setup<\/h2>\n<p>In this step, I will create a maven project with the Junit library.<\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n\txsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 https:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n\t&lt;groupId&gt;org.zheng.demo&lt;\/groupId&gt;\n\t&lt;artifactId&gt;convert_short_to_bytearray&lt;\/artifactId&gt;\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\n\t&lt;build&gt;\n\t\t&lt;plugins&gt;\n\t\t\t&lt;plugin&gt;\n\t\t\t\t&lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt;\n\t\t\t\t&lt;version&gt;3.8.1&lt;\/version&gt;\n\t\t\t\t&lt;configuration&gt;\n\t\t\t\t\t&lt;release&gt;17&lt;\/release&gt;\n\t\t\t\t&lt;\/configuration&gt;\n\t\t\t&lt;\/plugin&gt;\n\t\t&lt;\/plugins&gt;\n\t&lt;\/build&gt;\n\n\t&lt;dependencies&gt;\n\t\t&lt;!-- junit 5 --&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.junit.jupiter&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;junit-jupiter-engine&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;5.5.2&lt;\/version&gt;\n\t\t\t&lt;scope&gt;test&lt;\/scope&gt;\n\t\t&lt;\/dependency&gt;\n\t&lt;\/dependencies&gt;\n&lt;\/project&gt;<\/pre>\n<h2 class=\"wp-block-heading\">3. Junit Test Class<\/h2>\n<p>In this step, I will convert a short value to a byte array with three tests.<\/p>\n<p><span style=\"text-decoration: underline\"><em>TestConvertShortToByteArray.java<\/em><\/span><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java highlight:[18,25,37]\">package convert_short_to_bytearray;\n\nimport static org.junit.jupiter.api.Assertions.assertArrayEquals;\n\nimport java.io.ByteArrayOutputStream;\nimport java.io.DataOutputStream;\nimport java.io.IOException;\nimport java.nio.ByteBuffer;\n\nimport org.junit.jupiter.api.Test;\n\npublic class TestConvertShortToByteArray {\n\n\tshort shortValue = 32767;\n\tbyte[] expectedByteArray = { 127, -1 };\n\n\t@Test\n\tpublic void convertToByteArray_via_ByteBuffer() {\n\t\tbyte[] byteArray = ByteBuffer.allocate(Short.BYTES).putShort(shortValue).array();\n\n\t\tassertArrayEquals(expectedByteArray, byteArray);\n\t}\n\n\t@Test\n\tpublic void convertToByteArray_via_DataOutputStream() throws IOException {\n\t\ttry (ByteArrayOutputStream baos = new ByteArrayOutputStream();\n\t\t\t\tDataOutputStream dos = new DataOutputStream(baos)) {\n\t\t\t\n\t\t\tdos.writeShort(shortValue);\n\t\t\tbyte[] byteArray = baos.toByteArray();\n\t\t\t\n\t\t\tassertArrayEquals(expectedByteArray, byteArray);\n\t\t}\n\t}\n\n\t@Test\n\tpublic void convertToByteArray_via_BitShiftOperator() {\n\t\tbyte[] byteArray = new byte[Short.BYTES];\n\t\tbyteArray[0] = (byte) (shortValue &gt;&gt; 8);\n\t\tbyteArray[1] = (byte) shortValue;\n\n\t\tassertArrayEquals(expectedByteArray, byteArray);\n\t}\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>line 18: <code>convertToByteArray_via_ByteBuffer<\/code> &#8211; utilizes the <code>java.nio.ByteBuffer<\/code> class. See <a href=\"#step31\">step 3.1<\/a> for a detailed explanation.<\/li>\n<li>line 25: <code>convertToByteArray_via_DataOutputStream<\/code> &#8211; uses <code>java.io.ByteArrayOutputStream<\/code> class. See <a href=\"#step32\">step 3.2<\/a> for a detailed explanation.<\/li>\n<li>line 37: <code>convertToByteArray_via_BitShiftOperator<\/code> &#8211; uses the signed right shift operator. See <a href=\"#step33\">step 3.3<\/a> for a detailed explanation.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\"><a name=\"step31\"><\/a>3.1 Short Byte Array Conversion via ByteBuffer<\/h3>\n<p>We will convert a short to a byte array with three steps. <\/p>\n<ul class=\"wp-block-list\">\n<li>First, create a <code>ByteBuffer<\/code> object with the size of <code>Short.BYTES<\/code> via <code>ByteBuffer.allocate(Short.BYTES)<\/code><\/li>\n<li>Second, write the given short value via <code>putShort(shortValue)<\/code>.<\/li>\n<li>Last, invoke the <code>array<\/code> method to convert to a byte array.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\"><a name=\"step32\"><\/a>3.2 Short Byte Array Conversion via ByteArrayOutputStream<\/h3>\n<p>Following three steps to convert a short into a byte array. <\/p>\n<ul class=\"wp-block-list\">\n<li>First, create a <code>ByteArrayOutputStream<\/code> and <code>DataOutputStream<\/code> objects. <\/li>\n<li>Then write the short value via <code>dos.writeShort(shortValue)<\/code>. <\/li>\n<li>Finally, convert to a byte array via <code>baos.toByteArray()<\/code>;<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\"><a name=\"step33\"><\/a>3.3 Short Byte Array Conversion via Bit Shift Operator<\/h3>\n<p>A short in Java is a 16-bit signed integer and takes <code>2<\/code> bytes in memory. The first byte stores the high-order bits and the second byte stores the lower-order bits. In this step, I will use the &#8220;signed right shift operator&#8221; ( <code>&gt;&gt;)<\/code> to create a byte array from a short value.<\/p>\n<ul class=\"wp-block-list\">\n<li>The <code>shortValue &gt;&gt; 8<\/code> shifts the bits of <code>shortValue<\/code> to the right by 8 positions. This operation effectively isolates the most significant byte of the <code>shortValue<\/code> as the most significant byte (high-order byte) of a short is stored in the element at index 0 of <code>byte[]<\/code>.<\/li>\n<li>The least significant byte (low-order byte) is stored in the element at index 1 of <code>byte[]<\/code>.  The <code>(byte)<\/code> again casts <code>shortValue<\/code> to a <code>byte<\/code>, truncating the higher-order bits that do not fit into a byte.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">4. Run Test<\/h2>\n<p>In this step, I will run the tests and verify the tests are passed.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/07\/unittests.jpg\"><img decoding=\"async\" width=\"800\" height=\"323\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/07\/unittests.jpg\" alt=\"\" class=\"wp-image-124645\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/07\/unittests.jpg 800w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/07\/unittests-300x121.jpg 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/07\/unittests-768x310.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 1. Unit Tests Result<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">5. Conclusion<\/h2>\n<p>In this example, I demonstrated short byte array conversion in the following ways:<\/p>\n<ul class=\"wp-block-list\">\n<li>Using <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/ByteBuffer.html\" target=\"_blank\" rel=\"noreferrer noopener\">java.nio.ByteBuffer<\/a>&#8216;s <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/ByteBuffer.html#array--\" target=\"_blank\" rel=\"noreferrer noopener\">array<\/a> method.<\/li>\n<li>Using <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/io\/ByteArrayOutputStream.html\" target=\"_blank\" rel=\"noreferrer noopener\">java.io.ByteArrayOutputStream<\/a>&#8216;s <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/io\/ByteArrayOutputStream.html#toByteArray--\" target=\"_blank\" rel=\"noreferrer noopener\">toByteArray<\/a> method.<\/li>\n<li>Using the <a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/nutsandbolts\/op3.html\" target=\"_blank\" rel=\"noreferrer noopener\">signed right shift operator &gt;&gt;<\/a>.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">6. Download<\/h2>\n<p>This was an example of a maven project which converts a short value into a byte array.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/07\/convert_short_to_bytearray.zip\"><strong>Convert Short to Byte Array<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction Converting a short value to a byte array is a common task when dealing with binary data. In this example, I will demonstrate short byte array conversion in the following ways: Using java.nio.ByteBuffer&#8216;s array method. Using java.io.ByteArrayOutputStream&#8216;s toByteArray method. Using the signed right shift operator &gt;&gt;. 2. Setup In this step, I will &hellip;<\/p>\n","protected":false},"author":128892,"featured_media":148,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[110,2727],"class_list":["post-124642","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-byte-array","tag-short"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Convert Short to Byte Array - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn more about short byte array conversion? Then check out our detailed example!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Convert Short to Byte Array - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about short byte array conversion? Then check out our detailed example!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-08T08:59:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-08T08:59:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Mary Zheng\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mary Zheng\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html\"},\"author\":{\"name\":\"Mary Zheng\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/33e795ab61de7fab61ed89b4de1668f5\"},\"headline\":\"Convert Short to Byte Array\",\"datePublished\":\"2024-07-08T08:59:49+00:00\",\"dateModified\":\"2024-07-08T08:59:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html\"},\"wordCount\":426,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"keywords\":[\"Byte array\",\"short\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html\",\"name\":\"Convert Short to Byte Array - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"datePublished\":\"2024-07-08T08:59:49+00:00\",\"dateModified\":\"2024-07-08T08:59:51+00:00\",\"description\":\"Interested to learn more about short byte array conversion? Then check out our detailed example!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/convert-short-to-byte-array.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/core-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Convert Short to Byte Array\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/33e795ab61de7fab61ed89b4de1668f5\",\"name\":\"Mary Zheng\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"caption\":\"Mary Zheng\"},\"description\":\"Mary graduated from the Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She worked as a lead Software Engineer where she led and worked with others to design, implement, and monitor the software solution.\",\"sameAs\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/mary-zheng\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Convert Short to Byte Array - Java Code Geeks","description":"Interested to learn more about short byte array conversion? Then check out our detailed example!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html","og_locale":"en_US","og_type":"article","og_title":"Convert Short to Byte Array - Java Code Geeks","og_description":"Interested to learn more about short byte array conversion? Then check out our detailed example!","og_url":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2024-07-08T08:59:49+00:00","article_modified_time":"2024-07-08T08:59:51+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","type":"image\/jpeg"}],"author":"Mary Zheng","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mary Zheng","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html"},"author":{"name":"Mary Zheng","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/33e795ab61de7fab61ed89b4de1668f5"},"headline":"Convert Short to Byte Array","datePublished":"2024-07-08T08:59:49+00:00","dateModified":"2024-07-08T08:59:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html"},"wordCount":426,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","keywords":["Byte array","short"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html","url":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html","name":"Convert Short to Byte Array - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","datePublished":"2024-07-08T08:59:49+00:00","dateModified":"2024-07-08T08:59:51+00:00","description":"Interested to learn more about short byte array conversion? Then check out our detailed example!","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/convert-short-to-byte-array.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/core-java"},{"@type":"ListItem","position":4,"name":"Convert Short to Byte Array"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/33e795ab61de7fab61ed89b4de1668f5","name":"Mary Zheng","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","caption":"Mary Zheng"},"description":"Mary graduated from the Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She worked as a lead Software Engineer where she led and worked with others to design, implement, and monitor the software solution.","sameAs":["https:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/mary-zheng"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/124642","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/128892"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=124642"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/124642\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=124642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=124642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=124642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}