Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8524159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:36:41+00:00 2026-06-11T07:36:41+00:00

I do: Dim BytArr() as Byte = BitConverter.GetBytes(1234) Since, by default, they are 32

  • 0

I do:

Dim BytArr() as Byte = BitConverter.GetBytes(1234)

Since, by default, they are 32 bits, it returns 4 byte elements.

I want to be able to control it to return only like two bytes. Maybe only three bytes. Are there any built-in functions to control it?

I don’t want to rely on using shifting >> 8 >> 16 >> 24 >> 32, etc..

I also don’t want to rely on type casting the data in GetBytes() to a specific datatype.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:36:43+00:00Added an answer on June 11, 2026 at 7:36 am

    It is not that GetBytes defaults to 32 bits, it is that GetBytes returns an array of the size required to hold the data type. If you pass a Long then you will get a 8 elements in your array.

    The best way to control this is indeed casting the data you pass in. Otherwise you could truncate some of the number.

    That being said, you could do something like this:

    Dim BytArr() as Byte = Array.Resize(BitConverter.GetBytes(1234), 2)
    

    But if the value you passed in exceeded what could be stored in 2 bytes (in this case) then you will have some very broken code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example code: Dim a As String a = 1234,5678,9123 I want to add literal
dim dataType as String toolTip=Marks And Number[String] I want to get the [String] alone.
Dim root As XElement = XElement.Load(xmlFile) Dim stuff = From item In root.Elements(abc) Select
Dim str as String str = 30 40 50 60 I want to count
Dim dtmStart As Date, dtmEnd As Date, dblDuration As Double dtmStart = 1900/01/01 08:10:00
Dim classCodeDetails As List(Of ClassCodeDetail) = db.ClassCodeHeaders.Single(Function(cch) cch.CLCH_ID = classCodeHeaderId ).ClassCodeDetails.ToList() classCodeDetails.Sort(Function(c1, c2) c1.Make.MAKE_English.CompareTo(c2.Make.MAKE_English)
Dim xbg As Rm xbg.LobId = cmb_lob.SelectedValue xbg.Mobile = mobno.Text xbg.BusinessFax = faxno.Text xbg.BusinessPhone
Dim objMail As New Mail.MailMessage(no-reply@mywebsite.com, ToEmail, Password Reset, body) ...and the problem is that
Dim MyQuery = From c In xdoc.Descendants() _ Where c.Attribute(OriginY) IsNot Nothing _ Order
dim shell,x,y x=D:\d y=c.bat & x set shell=createobject(wscript.shell) shell.run y shell.run a.bat set shell=nothing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.