473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Convert Long Integer to Binary byte

How can I convert a long integer to binary? For example, I want the integer 725 to show up as 1011010101 in another field in the table. Each of the bits in the byte are representative of the state of a different piece of machinery.
Sep 12 '14 #1
3 5575
Seth Schrock
2,965 Expert 2GB
A quick Google search returned this: VBA - Converting Between Decimal and Binary. One thing you should note, the binary "number" is actually a string data type, so if you are storing the binary data in a table, the field will need to be Text.
Sep 12 '14 #2
jforbes
1,107 Expert 1GB
Here you go:

Expand|Select|Wrap|Line Numbers
  1. Public Function getBinary(ByRef iDec As Integer, ByRef iResolution As Integer) As String
  2.     Dim iCount As Integer
  3.     getBinary = ""
  4.     For iCount = iResolution - 1 To 0 Step -1
  5.         getBinary = getBinary + IIf(iDec And (2 ^ iCount), "1", "0")
  6.     Next iCount
  7. End Function
Parameter 1 to is the Decimal value, Parameter 2 is how many place holders you would like.

This is just the function, you may need to resort to a query to get this returned to you on every line in the table.
Sep 12 '14 #3
NeoPa
32,556 Expert Mod 16PB
I don't believe there is an inbuilt Binary() function like the Hex() function.

Here's a function you can include in your project that should do a similar job. You may decide you need to be able to specify the number of digits. If so that's pretty easy to handle.
Expand|Select|Wrap|Line Numbers
  1. Public Function DispBinary(ByVal lngVar As Long) As String
  2.     Do While lngVar > 0
  3.         DispBinary = Format(lngVar And &H01, "0") & DispBinary
  4.         lngVar = Int(lngVar / 2)
  5.     Loop
  6. End Function
Sep 13 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: italia | last post by:
I changed the Fieldsize Property from text to Long Integer and Decimal Places = 6. I had decimals in the original field. But after the transfer, the digits after the decimals are gone. Now...
3
by: seema | last post by:
I am working under a Linux environment, and I want to convert a long int into a string. It looks doesnt't have a function such ltoa,itoa on stdlib. How Can I do that? I tried to work with double...
6
by: MrKrich | last post by:
I want to convert Hexadecimal or normal integer to Binary. Does VB.Net has function to do that? I only found Hex function that convert normal integer to Hexadecimal.
43
by: Steven T. Hatton | last post by:
http://public.research.att.com/~bs/bs_faq2.html#int-to-string Is there no C library function that will take an int and convert it to its ascii representation? The example Bjarne shows in his faq...
10
by: rodrigo.gloria | last post by:
I am trying to convert a integer to an address of a function pointer. I want to encrypt the pointer and then do some validation, afterwards i will decrpyt the pointer back to an address. Can...
7
by: wenmang | last post by:
what is format for sprintf to convert long long integer (64 bits) to string?
27
by: fdu.xiaojf | last post by:
Hi, String formatting can be used to converting an integer to its octal or hexadecimal form: '307' 'c7' But, can string formatting be used to convert an integer to its binary form ?
1
by: Christian Reizlein | last post by:
How do i convert an integer value to a byte array?
8
by: dinklebaga | last post by:
Hi All, I am writing a function at the moment to calculate the value of an byte offset for a floppy disk image but for some reason the long integer I am using to store this value is signed despite...
1
by: iamef | last post by:
Dear All, Is there a way to convert long decimal int value to 4-bytes, using Bourne Shell or any commands from minimal Linux (sed, awk, etc)? The goal is to calculate size of file and place the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.